


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using SubSonic.DataProviders;
using SubSonic.Extensions;
using System.Linq.Expressions;
using SubSonic.Schema;
using System.Collections;
using SubSonic;
using SubSonic.Repository;
using System.ComponentModel;
using System.Data.Common;

namespace Amortyzacje.Model
{
    
    
    /// <summary>
    /// A class which represents the Adres table in the evolution Database.
    /// </summary>
    public partial class Adre: IActiveRecord
    {
    
        #region Built-in testing
        static TestRepository<Adre> _testRepo;
        

        
        static void SetTestRepo(){
            _testRepo = _testRepo ?? new TestRepository<Adre>(new Amortyzacje.Model.evolutionDB());
        }
        public static void ResetTestRepo(){
            _testRepo = null;
            SetTestRepo();
        }
        public static void Setup(List<Adre> testlist){
            SetTestRepo();
            foreach (var item in testlist)
            {
                _testRepo._items.Add(item);
            }
        }
        public static void Setup(Adre item) {
            SetTestRepo();
            _testRepo._items.Add(item);
        }
        public static void Setup(int testItems) {
            SetTestRepo();
            for(int i=0;i<testItems;i++){
                Adre item=new Adre();
                _testRepo._items.Add(item);
            }
        }
        
        public bool TestMode = false;


        #endregion

        IRepository<Adre> _repo;
        ITable tbl;
        bool _isNew;
        public bool IsNew(){
            return _isNew;
        }
        
        public void SetIsLoaded(bool isLoaded){
            _isLoaded=isLoaded;
            if(isLoaded)
                OnLoaded();
        }
        
        public void SetIsNew(bool isNew){
            _isNew=isNew;
        }
        bool _isLoaded;
        public bool IsLoaded(){
            return _isLoaded;
        }
                
        List<IColumn> _dirtyColumns;
        public bool IsDirty(){
            return _dirtyColumns.Count>0;
        }
        
        public List<IColumn> GetDirtyColumns (){
            return _dirtyColumns;
        }

        Amortyzacje.Model.evolutionDB _db;
        public Adre(string connectionString, string providerName) {

            _db=new Amortyzacje.Model.evolutionDB(connectionString, providerName);
            Init();            
         }
        void Init(){
            TestMode=this._db.DataProvider.ConnectionString.Equals("test", StringComparison.InvariantCultureIgnoreCase);
            _dirtyColumns=new List<IColumn>();
            if(TestMode){
                Adre.SetTestRepo();
                _repo=_testRepo;
            }else{
                _repo = new SubSonicRepository<Adre>(_db);
            }
            tbl=_repo.GetTable();
            SetIsNew(true);
            OnCreated();       

        }
        
        public Adre(){
             _db=new Amortyzacje.Model.evolutionDB();
            Init();            
        }
        
       
        partial void OnCreated();
            
        partial void OnLoaded();
        
        partial void OnSaved();
        
        partial void OnChanged();
        
        public IList<IColumn> Columns{
            get{
                return tbl.Columns;
            }
        }

        public Adre(Expression<Func<Adre, bool>> expression):this() {

            SetIsLoaded(_repo.Load(this,expression));
        }
        
       
        
        internal static IRepository<Adre> GetRepo(string connectionString, string providerName){
            Amortyzacje.Model.evolutionDB db;
            if(String.IsNullOrEmpty(connectionString)){
                db=new Amortyzacje.Model.evolutionDB();
            }else{
                db=new Amortyzacje.Model.evolutionDB(connectionString, providerName);
            }
            IRepository<Adre> _repo;
            
            if(db.TestMode){
                Adre.SetTestRepo();
                _repo=_testRepo;
            }else{
                _repo = new SubSonicRepository<Adre>(db);
            }
            return _repo;        
        }       
        
        internal static IRepository<Adre> GetRepo(){
            return GetRepo("","");
        }
        
        public static Adre SingleOrDefault(Expression<Func<Adre, bool>> expression) {

            var repo = GetRepo();
            var results=repo.Find(expression);
            Adre single=null;
            if(results.Count() > 0){
                single=results.ToList()[0];
                single.OnLoaded();
                single.SetIsLoaded(true);
                single.SetIsNew(false);
            }

            return single;
        }      
        
        public static Adre SingleOrDefault(Expression<Func<Adre, bool>> expression,string connectionString, string providerName) {
            var repo = GetRepo(connectionString,providerName);
            var results=repo.Find(expression);
            Adre single=null;
            if(results.Count() > 0){
                single=results.ToList()[0];
            }

            return single;


        }
        
        
        public static bool Exists(Expression<Func<Adre, bool>> expression,string connectionString, string providerName) {
           
            return All(connectionString,providerName).Any(expression);
        }        
        public static bool Exists(Expression<Func<Adre, bool>> expression) {
           
            return All().Any(expression);
        }        

        public static IList<Adre> Find(Expression<Func<Adre, bool>> expression) {
            
            var repo = GetRepo();
            return repo.Find(expression).ToList();
        }
        
        public static IList<Adre> Find(Expression<Func<Adre, bool>> expression,string connectionString, string providerName) {

            var repo = GetRepo(connectionString,providerName);
            return repo.Find(expression).ToList();

        }
        public static IQueryable<Adre> All(string connectionString, string providerName) {
            return GetRepo(connectionString,providerName).GetAll();
        }
        public static IQueryable<Adre> All() {
            return GetRepo().GetAll();
        }
        
        public static PagedList<Adre> GetPaged(string sortBy, int pageIndex, int pageSize,string connectionString, string providerName) {
            return GetRepo(connectionString,providerName).GetPaged(sortBy, pageIndex, pageSize);
        }
      
        public static PagedList<Adre> GetPaged(string sortBy, int pageIndex, int pageSize) {
            return GetRepo().GetPaged(sortBy, pageIndex, pageSize);
        }

        public static PagedList<Adre> GetPaged(int pageIndex, int pageSize,string connectionString, string providerName) {
            return GetRepo(connectionString,providerName).GetPaged(pageIndex, pageSize);
            
        }


        public static PagedList<Adre> GetPaged(int pageIndex, int pageSize) {
            return GetRepo().GetPaged(pageIndex, pageSize);
            
        }

        public string KeyName()
        {
            return "id";
        }

        public object KeyValue()
        {
            return this.id;
        }
        
        public void SetKeyValue(object value) {
            if (value != null && value!=DBNull.Value) {
                var settable = value.ChangeTypeTo<int>();
                this.GetType().GetProperty(this.KeyName()).SetValue(this, settable, null);
            }
        }
        
        public override string ToString(){
                            return this.miejscowosc.ToString();
                    }

        public override bool Equals(object obj){
            if(obj.GetType()==typeof(Adre)){
                Adre compare=(Adre)obj;
                return compare.KeyValue()==this.KeyValue();
            }else{
                return base.Equals(obj);
            }
        }

        
        public override int GetHashCode() {
            return this.id;
        }
        
        public string DescriptorValue()
        {
                            return this.miejscowosc.ToString();
                    }

        public string DescriptorColumn() {
            return "miejscowosc";
        }
        public static string GetKeyColumn()
        {
            return "id";
        }        
        public static string GetDescriptorColumn()
        {
            return "miejscowosc";
        }
        
        #region ' Foreign Keys '
        #endregion
        

        int _id;
        public int id
        {
            get { return _id; }
            set
            {
                if(_id!=value){
                    _id=value;
                    var col=tbl.Columns.SingleOrDefault(x=>x.Name=="id");
                    if(col!=null){
                        if(!_dirtyColumns.Any(x=>x.Name==col.Name) && _isLoaded){
                            _dirtyColumns.Add(col);
                        }
                    }
                    OnChanged();
                }
            }
        }

        int? _id_prac;
        public int? id_prac
        {
            get { return _id_prac; }
            set
            {
                if(_id_prac!=value){
                    _id_prac=value;
                    var col=tbl.Columns.SingleOrDefault(x=>x.Name=="id_prac");
                    if(col!=null){
                        if(!_dirtyColumns.Any(x=>x.Name==col.Name) && _isLoaded){
                            _dirtyColumns.Add(col);
                        }
                    }
                    OnChanged();
                }
            }
        }

        string _miejscowosc;
        public string miejscowosc
        {
            get { return _miejscowosc; }
            set
            {
                if(_miejscowosc!=value){
                    _miejscowosc=value;
                    var col=tbl.Columns.SingleOrDefault(x=>x.Name=="miejscowosc");
                    if(col!=null){
                        if(!_dirtyColumns.Any(x=>x.Name==col.Name) && _isLoaded){
                            _dirtyColumns.Add(col);
                        }
                    }
                    OnChanged();
                }
            }
        }

        string _powiat;
        public string powiat
        {
            get { return _powiat; }
            set
            {
                if(_powiat!=value){
                    _powiat=value;
                    var col=tbl.Columns.SingleOrDefault(x=>x.Name=="powiat");
                    if(col!=null){
                        if(!_dirtyColumns.Any(x=>x.Name==col.Name) && _isLoaded){
                            _dirtyColumns.Add(col);
                        }
                    }
                    OnChanged();
                }
            }
        }

        string _gminaDzielnica;
        public string gminaDzielnica
        {
            get { return _gminaDzielnica; }
            set
            {
                if(_gminaDzielnica!=value){
                    _gminaDzielnica=value;
                    var col=tbl.Columns.SingleOrDefault(x=>x.Name=="gminaDzielnica");
                    if(col!=null){
                        if(!_dirtyColumns.Any(x=>x.Name==col.Name) && _isLoaded){
                            _dirtyColumns.Add(col);
                        }
                    }
                    OnChanged();
                }
            }
        }

        string _wojewodztwo;
        public string wojewodztwo
        {
            get { return _wojewodztwo; }
            set
            {
                if(_wojewodztwo!=value){
                    _wojewodztwo=value;
                    var col=tbl.Columns.SingleOrDefault(x=>x.Name=="wojewodztwo");
                    if(col!=null){
                        if(!_dirtyColumns.Any(x=>x.Name==col.Name) && _isLoaded){
                            _dirtyColumns.Add(col);
                        }
                    }
                    OnChanged();
                }
            }
        }

        string _ulica;
        public string ulica
        {
            get { return _ulica; }
            set
            {
                if(_ulica!=value){
                    _ulica=value;
                    var col=tbl.Columns.SingleOrDefault(x=>x.Name=="ulica");
                    if(col!=null){
                        if(!_dirtyColumns.Any(x=>x.Name==col.Name) && _isLoaded){
                            _dirtyColumns.Add(col);
                        }
                    }
                    OnChanged();
                }
            }
        }

        string _nrDomu;
        public string nrDomu
        {
            get { return _nrDomu; }
            set
            {
                if(_nrDomu!=value){
                    _nrDomu=value;
                    var col=tbl.Columns.SingleOrDefault(x=>x.Name=="nrDomu");
                    if(col!=null){
                        if(!_dirtyColumns.Any(x=>x.Name==col.Name) && _isLoaded){
                            _dirtyColumns.Add(col);
                        }
                    }
                    OnChanged();
                }
            }
        }

        string _nrLokalu;
        public string nrLokalu
        {
            get { return _nrLokalu; }
            set
            {
                if(_nrLokalu!=value){
                    _nrLokalu=value;
                    var col=tbl.Columns.SingleOrDefault(x=>x.Name=="nrLokalu");
                    if(col!=null){
                        if(!_dirtyColumns.Any(x=>x.Name==col.Name) && _isLoaded){
                            _dirtyColumns.Add(col);
                        }
                    }
                    OnChanged();
                }
            }
        }

        string _kodPocztowy;
        public string kodPocztowy
        {
            get { return _kodPocztowy; }
            set
            {
                if(_kodPocztowy!=value){
                    _kodPocztowy=value;
                    var col=tbl.Columns.SingleOrDefault(x=>x.Name=="kodPocztowy");
                    if(col!=null){
                        if(!_dirtyColumns.Any(x=>x.Name==col.Name) && _isLoaded){
                            _dirtyColumns.Add(col);
                        }
                    }
                    OnChanged();
                }
            }
        }

        string _poczta;
        public string poczta
        {
            get { return _poczta; }
            set
            {
                if(_poczta!=value){
                    _poczta=value;
                    var col=tbl.Columns.SingleOrDefault(x=>x.Name=="poczta");
                    if(col!=null){
                        if(!_dirtyColumns.Any(x=>x.Name==col.Name) && _isLoaded){
                            _dirtyColumns.Add(col);
                        }
                    }
                    OnChanged();
                }
            }
        }



        public DbCommand GetUpdateCommand() {
            if(TestMode)
                return _db.DataProvider.CreateCommand();
            else
                return this.ToUpdateQuery(_db.Provider).GetCommand().ToDbCommand();
            
        }
        public DbCommand GetInsertCommand() {
 
            if(TestMode)
                return _db.DataProvider.CreateCommand();
            else
                return this.ToInsertQuery(_db.Provider).GetCommand().ToDbCommand();
        }
        
        public DbCommand GetDeleteCommand() {
            if(TestMode)
                return _db.DataProvider.CreateCommand();
            else
                return this.ToDeleteQuery(_db.Provider).GetCommand().ToDbCommand();
        }
       
        
        public void Update(){
            Update(_db.DataProvider);
        }
        
        public void Update(IDataProvider provider){
        
            
            if(this._dirtyColumns.Count>0){
                _repo.Update(this,provider);
                _dirtyColumns.Clear();    
            }
            OnSaved();
       }
 
        public void Add(){
            Add(_db.DataProvider);
        }
        
        
       
        public void Add(IDataProvider provider){

            
            var key=KeyValue();
            if(key==null){
                var newKey=_repo.Add(this,provider);
                this.SetKeyValue(newKey);
            }else{
                _repo.Add(this,provider);
            }
            SetIsNew(false);
            OnSaved();
        }
        
                
        
        public void Save() {
            Save(_db.DataProvider);
        }      
        public void Save(IDataProvider provider) {
            
           
            if (_isNew) {
                Add(provider);
                
            } else {
                Update(provider);
            }
            
        }

        

        public void Delete(IDataProvider provider) {
                   
                 
            _repo.Delete(KeyValue());
            
                    }


        public void Delete() {
            Delete(_db.DataProvider);
        }


        public static void Delete(Expression<Func<Adre, bool>> expression) {
            var repo = GetRepo();
            
       
            
            repo.DeleteMany(expression);
            
        }

        

        public void Load(IDataReader rdr) {
            Load(rdr, true);
        }
        public void Load(IDataReader rdr, bool closeReader) {
            if (rdr.Read()) {

                try {
                    rdr.Load(this);
                    SetIsNew(false);
                    SetIsLoaded(true);
                } catch {
                    SetIsLoaded(false);
                    throw;
                }
            }else{
                SetIsLoaded(false);
            }

            if (closeReader)
                rdr.Dispose();
        }
        

    } 
    
    
    /// <summary>
    /// A class which represents the Dzieci table in the evolution Database.
    /// </summary>
    public partial class Dzieci: IActiveRecord
    {
    
        #region Built-in testing
        static TestRepository<Dzieci> _testRepo;
        

        
        static void SetTestRepo(){
            _testRepo = _testRepo ?? new TestRepository<Dzieci>(new Amortyzacje.Model.evolutionDB());
        }
        public static void ResetTestRepo(){
            _testRepo = null;
            SetTestRepo();
        }
        public static void Setup(List<Dzieci> testlist){
            SetTestRepo();
            foreach (var item in testlist)
            {
                _testRepo._items.Add(item);
            }
        }
        public static void Setup(Dzieci item) {
            SetTestRepo();
            _testRepo._items.Add(item);
        }
        public static void Setup(int testItems) {
            SetTestRepo();
            for(int i=0;i<testItems;i++){
                Dzieci item=new Dzieci();
                _testRepo._items.Add(item);
            }
        }
        
        public bool TestMode = false;


        #endregion

        IRepository<Dzieci> _repo;
        ITable tbl;
        bool _isNew;
        public bool IsNew(){
            return _isNew;
        }
        
        public void SetIsLoaded(bool isLoaded){
            _isLoaded=isLoaded;
            if(isLoaded)
                OnLoaded();
        }
        
        public void SetIsNew(bool isNew){
            _isNew=isNew;
        }
        bool _isLoaded;
        public bool IsLoaded(){
            return _isLoaded;
        }
                
        List<IColumn> _dirtyColumns;
        public bool IsDirty(){
            return _dirtyColumns.Count>0;
        }
        
        public List<IColumn> GetDirtyColumns (){
            return _dirtyColumns;
        }

        Amortyzacje.Model.evolutionDB _db;
        public Dzieci(string connectionString, string providerName) {

            _db=new Amortyzacje.Model.evolutionDB(connectionString, providerName);
            Init();            
         }
        void Init(){
            TestMode=this._db.DataProvider.ConnectionString.Equals("test", StringComparison.InvariantCultureIgnoreCase);
            _dirtyColumns=new List<IColumn>();
            if(TestMode){
                Dzieci.SetTestRepo();
                _repo=_testRepo;
            }else{
                _repo = new SubSonicRepository<Dzieci>(_db);
            }
            tbl=_repo.GetTable();
            SetIsNew(true);
            OnCreated();       

        }
        
        public Dzieci(){
             _db=new Amortyzacje.Model.evolutionDB();
            Init();            
        }
        
       
        partial void OnCreated();
            
        partial void OnLoaded();
        
        partial void OnSaved();
        
        partial void OnChanged();
        
        public IList<IColumn> Columns{
            get{
                return tbl.Columns;
            }
        }

        public Dzieci(Expression<Func<Dzieci, bool>> expression):this() {

            SetIsLoaded(_repo.Load(this,expression));
        }
        
       
        
        internal static IRepository<Dzieci> GetRepo(string connectionString, string providerName){
            Amortyzacje.Model.evolutionDB db;
            if(String.IsNullOrEmpty(connectionString)){
                db=new Amortyzacje.Model.evolutionDB();
            }else{
                db=new Amortyzacje.Model.evolutionDB(connectionString, providerName);
            }
            IRepository<Dzieci> _repo;
            
            if(db.TestMode){
                Dzieci.SetTestRepo();
                _repo=_testRepo;
            }else{
                _repo = new SubSonicRepository<Dzieci>(db);
            }
            return _repo;        
        }       
        
        internal static IRepository<Dzieci> GetRepo(){
            return GetRepo("","");
        }
        
        public static Dzieci SingleOrDefault(Expression<Func<Dzieci, bool>> expression) {

            var repo = GetRepo();
            var results=repo.Find(expression);
            Dzieci single=null;
            if(results.Count() > 0){
                single=results.ToList()[0];
                single.OnLoaded();
                single.SetIsLoaded(true);
                single.SetIsNew(false);
            }

            return single;
        }      
        
        public static Dzieci SingleOrDefault(Expression<Func<Dzieci, bool>> expression,string connectionString, string providerName) {
            var repo = GetRepo(connectionString,providerName);
            var results=repo.Find(expression);
            Dzieci single=null;
            if(results.Count() > 0){
                single=results.ToList()[0];
            }

            return single;


        }
        
        
        public static bool Exists(Expression<Func<Dzieci, bool>> expression,string connectionString, string providerName) {
           
            return All(connectionString,providerName).Any(expression);
        }        
        public static bool Exists(Expression<Func<Dzieci, bool>> expression) {
           
            return All().Any(expression);
        }        

        public static IList<Dzieci> Find(Expression<Func<Dzieci, bool>> expression) {
            
            var repo = GetRepo();
            return repo.Find(expression).ToList();
        }
        
        public static IList<Dzieci> Find(Expression<Func<Dzieci, bool>> expression,string connectionString, string providerName) {

            var repo = GetRepo(connectionString,providerName);
            return repo.Find(expression).ToList();

        }
        public static IQueryable<Dzieci> All(string connectionString, string providerName) {
            return GetRepo(connectionString,providerName).GetAll();
        }
        public static IQueryable<Dzieci> All() {
            return GetRepo().GetAll();
        }
        
        public static PagedList<Dzieci> GetPaged(string sortBy, int pageIndex, int pageSize,string connectionString, string providerName) {
            return GetRepo(connectionString,providerName).GetPaged(sortBy, pageIndex, pageSize);
        }
      
        public static PagedList<Dzieci> GetPaged(string sortBy, int pageIndex, int pageSize) {
            return GetRepo().GetPaged(sortBy, pageIndex, pageSize);
        }

        public static PagedList<Dzieci> GetPaged(int pageIndex, int pageSize,string connectionString, string providerName) {
            return GetRepo(connectionString,providerName).GetPaged(pageIndex, pageSize);
            
        }


        public static PagedList<Dzieci> GetPaged(int pageIndex, int pageSize) {
            return GetRepo().GetPaged(pageIndex, pageSize);
            
        }

        public string KeyName()
        {
            return "id";
        }

        public object KeyValue()
        {
            return this.id;
        }
        
        public void SetKeyValue(object value) {
            if (value != null && value!=DBNull.Value) {
                var settable = value.ChangeTypeTo<int>();
                this.GetType().GetProperty(this.KeyName()).SetValue(this, settable, null);
            }
        }
        
        public override string ToString(){
                            return this.imieDziecka.ToString();
                    }

        public override bool Equals(object obj){
            if(obj.GetType()==typeof(Dzieci)){
                Dzieci compare=(Dzieci)obj;
                return compare.KeyValue()==this.KeyValue();
            }else{
                return base.Equals(obj);
            }
        }

        
        public override int GetHashCode() {
            return this.id;
        }
        
        public string DescriptorValue()
        {
                            return this.imieDziecka.ToString();
                    }

        public string DescriptorColumn() {
            return "imieDziecka";
        }
        public static string GetKeyColumn()
        {
            return "id";
        }        
        public static string GetDescriptorColumn()
        {
            return "imieDziecka";
        }
        
        #region ' Foreign Keys '
        #endregion
        

        int _id;
        public int id
        {
            get { return _id; }
            set
            {
                if(_id!=value){
                    _id=value;
                    var col=tbl.Columns.SingleOrDefault(x=>x.Name=="id");
                    if(col!=null){
                        if(!_dirtyColumns.Any(x=>x.Name==col.Name) && _isLoaded){
                            _dirtyColumns.Add(col);
                        }
                    }
                    OnChanged();
                }
            }
        }

        int? _id_prac;
        public int? id_prac
        {
            get { return _id_prac; }
            set
            {
                if(_id_prac!=value){
                    _id_prac=value;
                    var col=tbl.Columns.SingleOrDefault(x=>x.Name=="id_prac");
                    if(col!=null){
                        if(!_dirtyColumns.Any(x=>x.Name==col.Name) && _isLoaded){
                            _dirtyColumns.Add(col);
                        }
                    }
                    OnChanged();
                }
            }
        }

        string _imieDziecka;
        public string imieDziecka
        {
            get { return _imieDziecka; }
            set
            {
                if(_imieDziecka!=value){
                    _imieDziecka=value;
                    var col=tbl.Columns.SingleOrDefault(x=>x.Name=="imieDziecka");
                    if(col!=null){
                        if(!_dirtyColumns.Any(x=>x.Name==col.Name) && _isLoaded){
                            _dirtyColumns.Add(col);
                        }
                    }
                    OnChanged();
                }
            }
        }

        string _nazwiskoDziecka;
        public string nazwiskoDziecka
        {
            get { return _nazwiskoDziecka; }
            set
            {
                if(_nazwiskoDziecka!=value){
                    _nazwiskoDziecka=value;
                    var col=tbl.Columns.SingleOrDefault(x=>x.Name=="nazwiskoDziecka");
                    if(col!=null){
                        if(!_dirtyColumns.Any(x=>x.Name==col.Name) && _isLoaded){
                            _dirtyColumns.Add(col);
                        }
                    }
                    OnChanged();
                }
            }
        }

        string _nrPeselDziecka;
        public string nrPeselDziecka
        {
            get { return _nrPeselDziecka; }
            set
            {
                if(_nrPeselDziecka!=value){
                    _nrPeselDziecka=value;
                    var col=tbl.Columns.SingleOrDefault(x=>x.Name=="nrPeselDziecka");
                    if(col!=null){
                        if(!_dirtyColumns.Any(x=>x.Name==col.Name) && _isLoaded){
                            _dirtyColumns.Add(col);
                        }
                    }
                    OnChanged();
                }
            }
        }

        string _dataUrodzeniaDziecka;
        public string dataUrodzeniaDziecka
        {
            get { return _dataUrodzeniaDziecka; }
            set
            {
                if(_dataUrodzeniaDziecka!=value){
                    _dataUrodzeniaDziecka=value;
                    var col=tbl.Columns.SingleOrDefault(x=>x.Name=="dataUrodzeniaDziecka");
                    if(col!=null){
                        if(!_dirtyColumns.Any(x=>x.Name==col.Name) && _isLoaded){
                            _dirtyColumns.Add(col);
                        }
                    }
                    OnChanged();
                }
            }
        }

        bool? _naUtrzymaniuRodzica;
        public bool? naUtrzymaniuRodzica
        {
            get { return _naUtrzymaniuRodzica; }
            set
            {
                if(_naUtrzymaniuRodzica!=value){
                    _naUtrzymaniuRodzica=value;
                    var col=tbl.Columns.SingleOrDefault(x=>x.Name=="naUtrzymaniuRodzica");
                    if(col!=null){
                        if(!_dirtyColumns.Any(x=>x.Name==col.Name) && _isLoaded){
                            _dirtyColumns.Add(col);
                        }
                    }
                    OnChanged();
                }
            }
        }

        bool? _przyslugujeRodzinne;
        public bool? przyslugujeRodzinne
        {
            get { return _przyslugujeRodzinne; }
            set
            {
                if(_przyslugujeRodzinne!=value){
                    _przyslugujeRodzinne=value;
                    var col=tbl.Columns.SingleOrDefault(x=>x.Name=="przyslugujeRodzinne");
                    if(col!=null){
                        if(!_dirtyColumns.Any(x=>x.Name==col.Name) && _isLoaded){
                            _dirtyColumns.Add(col);
                        }
                    }
                    OnChanged();
                }
            }
        }



        public DbCommand GetUpdateCommand() {
            if(TestMode)
                return _db.DataProvider.CreateCommand();
            else
                return this.ToUpdateQuery(_db.Provider).GetCommand().ToDbCommand();
            
        }
        public DbCommand GetInsertCommand() {
 
            if(TestMode)
                return _db.DataProvider.CreateCommand();
            else
                return this.ToInsertQuery(_db.Provider).GetCommand().ToDbCommand();
        }
        
        public DbCommand GetDeleteCommand() {
            if(TestMode)
                return _db.DataProvider.CreateCommand();
            else
                return this.ToDeleteQuery(_db.Provider).GetCommand().ToDbCommand();
        }
       
        
        public void Update(){
            Update(_db.DataProvider);
        }
        
        public void Update(IDataProvider provider){
        
            
            if(this._dirtyColumns.Count>0){
                _repo.Update(this,provider);
                _dirtyColumns.Clear();    
            }
            OnSaved();
       }
 
        public void Add(){
            Add(_db.DataProvider);
        }
        
        
       
        public void Add(IDataProvider provider){

            
            var key=KeyValue();
            if(key==null){
                var newKey=_repo.Add(this,provider);
                this.SetKeyValue(newKey);
            }else{
                _repo.Add(this,provider);
            }
            SetIsNew(false);
            OnSaved();
        }
        
                
        
        public void Save() {
            Save(_db.DataProvider);
        }      
        public void Save(IDataProvider provider) {
            
           
            if (_isNew) {
                Add(provider);
                
            } else {
                Update(provider);
            }
            
        }

        

        public void Delete(IDataProvider provider) {
                   
                 
            _repo.Delete(KeyValue());
            
                    }


        public void Delete() {
            Delete(_db.DataProvider);
        }


        public static void Delete(Expression<Func<Dzieci, bool>> expression) {
            var repo = GetRepo();
            
       
            
            repo.DeleteMany(expression);
            
        }

        

        public void Load(IDataReader rdr) {
            Load(rdr, true);
        }
        public void Load(IDataReader rdr, bool closeReader) {
            if (rdr.Read()) {

                try {
                    rdr.Load(this);
                    SetIsNew(false);
                    SetIsLoaded(true);
                } catch {
                    SetIsLoaded(false);
                    throw;
                }
            }else{
                SetIsLoaded(false);
            }

            if (closeReader)
                rdr.Dispose();
        }
        

    } 
    
    
    /// <summary>
    /// A class which represents the Powiadomienia table in the evolution Database.
    /// </summary>
    public partial class Powiadomienium: IActiveRecord
    {
    
        #region Built-in testing
        static TestRepository<Powiadomienium> _testRepo;
        

        
        static void SetTestRepo(){
            _testRepo = _testRepo ?? new TestRepository<Powiadomienium>(new Amortyzacje.Model.evolutionDB());
        }
        public static void ResetTestRepo(){
            _testRepo = null;
            SetTestRepo();
        }
        public static void Setup(List<Powiadomienium> testlist){
            SetTestRepo();
            foreach (var item in testlist)
            {
                _testRepo._items.Add(item);
            }
        }
        public static void Setup(Powiadomienium item) {
            SetTestRepo();
            _testRepo._items.Add(item);
        }
        public static void Setup(int testItems) {
            SetTestRepo();
            for(int i=0;i<testItems;i++){
                Powiadomienium item=new Powiadomienium();
                _testRepo._items.Add(item);
            }
        }
        
        public bool TestMode = false;


        #endregion

        IRepository<Powiadomienium> _repo;
        ITable tbl;
        bool _isNew;
        public bool IsNew(){
            return _isNew;
        }
        
        public void SetIsLoaded(bool isLoaded){
            _isLoaded=isLoaded;
            if(isLoaded)
                OnLoaded();
        }
        
        public void SetIsNew(bool isNew){
            _isNew=isNew;
        }
        bool _isLoaded;
        public bool IsLoaded(){
            return _isLoaded;
        }
                
        List<IColumn> _dirtyColumns;
        public bool IsDirty(){
            return _dirtyColumns.Count>0;
        }
        
        public List<IColumn> GetDirtyColumns (){
            return _dirtyColumns;
        }

        Amortyzacje.Model.evolutionDB _db;
        public Powiadomienium(string connectionString, string providerName) {

            _db=new Amortyzacje.Model.evolutionDB(connectionString, providerName);
            Init();            
         }
        void Init(){
            TestMode=this._db.DataProvider.ConnectionString.Equals("test", StringComparison.InvariantCultureIgnoreCase);
            _dirtyColumns=new List<IColumn>();
            if(TestMode){
                Powiadomienium.SetTestRepo();
                _repo=_testRepo;
            }else{
                _repo = new SubSonicRepository<Powiadomienium>(_db);
            }
            tbl=_repo.GetTable();
            SetIsNew(true);
            OnCreated();       

        }
        
        public Powiadomienium(){
             _db=new Amortyzacje.Model.evolutionDB();
            Init();            
        }
        
       
        partial void OnCreated();
            
        partial void OnLoaded();
        
        partial void OnSaved();
        
        partial void OnChanged();
        
        public IList<IColumn> Columns{
            get{
                return tbl.Columns;
            }
        }

        public Powiadomienium(Expression<Func<Powiadomienium, bool>> expression):this() {

            SetIsLoaded(_repo.Load(this,expression));
        }
        
       
        
        internal static IRepository<Powiadomienium> GetRepo(string connectionString, string providerName){
            Amortyzacje.Model.evolutionDB db;
            if(String.IsNullOrEmpty(connectionString)){
                db=new Amortyzacje.Model.evolutionDB();
            }else{
                db=new Amortyzacje.Model.evolutionDB(connectionString, providerName);
            }
            IRepository<Powiadomienium> _repo;
            
            if(db.TestMode){
                Powiadomienium.SetTestRepo();
                _repo=_testRepo;
            }else{
                _repo = new SubSonicRepository<Powiadomienium>(db);
            }
            return _repo;        
        }       
        
        internal static IRepository<Powiadomienium> GetRepo(){
            return GetRepo("","");
        }
        
        public static Powiadomienium SingleOrDefault(Expression<Func<Powiadomienium, bool>> expression) {

            var repo = GetRepo();
            var results=repo.Find(expression);
            Powiadomienium single=null;
            if(results.Count() > 0){
                single=results.ToList()[0];
                single.OnLoaded();
                single.SetIsLoaded(true);
                single.SetIsNew(false);
            }

            return single;
        }      
        
        public static Powiadomienium SingleOrDefault(Expression<Func<Powiadomienium, bool>> expression,string connectionString, string providerName) {
            var repo = GetRepo(connectionString,providerName);
            var results=repo.Find(expression);
            Powiadomienium single=null;
            if(results.Count() > 0){
                single=results.ToList()[0];
            }

            return single;


        }
        
        
        public static bool Exists(Expression<Func<Powiadomienium, bool>> expression,string connectionString, string providerName) {
           
            return All(connectionString,providerName).Any(expression);
        }        
        public static bool Exists(Expression<Func<Powiadomienium, bool>> expression) {
           
            return All().Any(expression);
        }        

        public static IList<Powiadomienium> Find(Expression<Func<Powiadomienium, bool>> expression) {
            
            var repo = GetRepo();
            return repo.Find(expression).ToList();
        }
        
        public static IList<Powiadomienium> Find(Expression<Func<Powiadomienium, bool>> expression,string connectionString, string providerName) {

            var repo = GetRepo(connectionString,providerName);
            return repo.Find(expression).ToList();

        }
        public static IQueryable<Powiadomienium> All(string connectionString, string providerName) {
            return GetRepo(connectionString,providerName).GetAll();
        }
        public static IQueryable<Powiadomienium> All() {
            return GetRepo().GetAll();
        }
        
        public static PagedList<Powiadomienium> GetPaged(string sortBy, int pageIndex, int pageSize,string connectionString, string providerName) {
            return GetRepo(connectionString,providerName).GetPaged(sortBy, pageIndex, pageSize);
        }
      
        public static PagedList<Powiadomienium> GetPaged(string sortBy, int pageIndex, int pageSize) {
            return GetRepo().GetPaged(sortBy, pageIndex, pageSize);
        }

        public static PagedList<Powiadomienium> GetPaged(int pageIndex, int pageSize,string connectionString, string providerName) {
            return GetRepo(connectionString,providerName).GetPaged(pageIndex, pageSize);
            
        }


        public static PagedList<Powiadomienium> GetPaged(int pageIndex, int pageSize) {
            return GetRepo().GetPaged(pageIndex, pageSize);
            
        }

        public string KeyName()
        {
            return "idPowiadomienia";
        }

        public object KeyValue()
        {
            return this.idPowiadomienia;
        }
        
        public void SetKeyValue(object value) {
            if (value != null && value!=DBNull.Value) {
                var settable = value.ChangeTypeTo<int>();
                this.GetType().GetProperty(this.KeyName()).SetValue(this, settable, null);
            }
        }
        
        public override string ToString(){
                            return this.Message.ToString();
                    }

        public override bool Equals(object obj){
            if(obj.GetType()==typeof(Powiadomienium)){
                Powiadomienium compare=(Powiadomienium)obj;
                return compare.KeyValue()==this.KeyValue();
            }else{
                return base.Equals(obj);
            }
        }

        
        public override int GetHashCode() {
            return this.idPowiadomienia;
        }
        
        public string DescriptorValue()
        {
                            return this.Message.ToString();
                    }

        public string DescriptorColumn() {
            return "Message";
        }
        public static string GetKeyColumn()
        {
            return "idPowiadomienia";
        }        
        public static string GetDescriptorColumn()
        {
            return "Message";
        }
        
        #region ' Foreign Keys '
        #endregion
        

        int _idPowiadomienia;
        public int idPowiadomienia
        {
            get { return _idPowiadomienia; }
            set
            {
                if(_idPowiadomienia!=value){
                    _idPowiadomienia=value;
                    var col=tbl.Columns.SingleOrDefault(x=>x.Name=="idPowiadomienia");
                    if(col!=null){
                        if(!_dirtyColumns.Any(x=>x.Name==col.Name) && _isLoaded){
                            _dirtyColumns.Add(col);
                        }
                    }
                    OnChanged();
                }
            }
        }

        int _Id_source;
        public int Id_source
        {
            get { return _Id_source; }
            set
            {
                if(_Id_source!=value){
                    _Id_source=value;
                    var col=tbl.Columns.SingleOrDefault(x=>x.Name=="Id_source");
                    if(col!=null){
                        if(!_dirtyColumns.Any(x=>x.Name==col.Name) && _isLoaded){
                            _dirtyColumns.Add(col);
                        }
                    }
                    OnChanged();
                }
            }
        }

        int _Id_dest;
        public int Id_dest
        {
            get { return _Id_dest; }
            set
            {
                if(_Id_dest!=value){
                    _Id_dest=value;
                    var col=tbl.Columns.SingleOrDefault(x=>x.Name=="Id_dest");
                    if(col!=null){
                        if(!_dirtyColumns.Any(x=>x.Name==col.Name) && _isLoaded){
                            _dirtyColumns.Add(col);
                        }
                    }
                    OnChanged();
                }
            }
        }

        string _Message;
        public string Message
        {
            get { return _Message; }
            set
            {
                if(_Message!=value){
                    _Message=value;
                    var col=tbl.Columns.SingleOrDefault(x=>x.Name=="Message");
                    if(col!=null){
                        if(!_dirtyColumns.Any(x=>x.Name==col.Name) && _isLoaded){
                            _dirtyColumns.Add(col);
                        }
                    }
                    OnChanged();
                }
            }
        }



        public DbCommand GetUpdateCommand() {
            if(TestMode)
                return _db.DataProvider.CreateCommand();
            else
                return this.ToUpdateQuery(_db.Provider).GetCommand().ToDbCommand();
            
        }
        public DbCommand GetInsertCommand() {
 
            if(TestMode)
                return _db.DataProvider.CreateCommand();
            else
                return this.ToInsertQuery(_db.Provider).GetCommand().ToDbCommand();
        }
        
        public DbCommand GetDeleteCommand() {
            if(TestMode)
                return _db.DataProvider.CreateCommand();
            else
                return this.ToDeleteQuery(_db.Provider).GetCommand().ToDbCommand();
        }
       
        
        public void Update(){
            Update(_db.DataProvider);
        }
        
        public void Update(IDataProvider provider){
        
            
            if(this._dirtyColumns.Count>0){
                _repo.Update(this,provider);
                _dirtyColumns.Clear();    
            }
            OnSaved();
       }
 
        public void Add(){
            Add(_db.DataProvider);
        }
        
        
       
        public void Add(IDataProvider provider){

            
            var key=KeyValue();
            if(key==null){
                var newKey=_repo.Add(this,provider);
                this.SetKeyValue(newKey);
            }else{
                _repo.Add(this,provider);
            }
            SetIsNew(false);
            OnSaved();
        }
        
                
        
        public void Save() {
            Save(_db.DataProvider);
        }      
        public void Save(IDataProvider provider) {
            
           
            if (_isNew) {
                Add(provider);
                
            } else {
                Update(provider);
            }
            
        }

        

        public void Delete(IDataProvider provider) {
                   
                 
            _repo.Delete(KeyValue());
            
                    }


        public void Delete() {
            Delete(_db.DataProvider);
        }


        public static void Delete(Expression<Func<Powiadomienium, bool>> expression) {
            var repo = GetRepo();
            
       
            
            repo.DeleteMany(expression);
            
        }

        

        public void Load(IDataReader rdr) {
            Load(rdr, true);
        }
        public void Load(IDataReader rdr, bool closeReader) {
            if (rdr.Read()) {

                try {
                    rdr.Load(this);
                    SetIsNew(false);
                    SetIsLoaded(true);
                } catch {
                    SetIsLoaded(false);
                    throw;
                }
            }else{
                SetIsLoaded(false);
            }

            if (closeReader)
                rdr.Dispose();
        }
        

    } 
    
    
    /// <summary>
    /// A class which represents the Pracownik table in the evolution Database.
    /// </summary>
    public partial class Pracownik: IActiveRecord
    {
    
        #region Built-in testing
        static TestRepository<Pracownik> _testRepo;
        

        
        static void SetTestRepo(){
            _testRepo = _testRepo ?? new TestRepository<Pracownik>(new Amortyzacje.Model.evolutionDB());
        }
        public static void ResetTestRepo(){
            _testRepo = null;
            SetTestRepo();
        }
        public static void Setup(List<Pracownik> testlist){
            SetTestRepo();
            foreach (var item in testlist)
            {
                _testRepo._items.Add(item);
            }
        }
        public static void Setup(Pracownik item) {
            SetTestRepo();
            _testRepo._items.Add(item);
        }
        public static void Setup(int testItems) {
            SetTestRepo();
            for(int i=0;i<testItems;i++){
                Pracownik item=new Pracownik();
                _testRepo._items.Add(item);
            }
        }
        
        public bool TestMode = false;


        #endregion

        IRepository<Pracownik> _repo;
        ITable tbl;
        bool _isNew;
        public bool IsNew(){
            return _isNew;
        }
        
        public void SetIsLoaded(bool isLoaded){
            _isLoaded=isLoaded;
            if(isLoaded)
                OnLoaded();
        }
        
        public void SetIsNew(bool isNew){
            _isNew=isNew;
        }
        bool _isLoaded;
        public bool IsLoaded(){
            return _isLoaded;
        }
                
        List<IColumn> _dirtyColumns;
        public bool IsDirty(){
            return _dirtyColumns.Count>0;
        }
        
        public List<IColumn> GetDirtyColumns (){
            return _dirtyColumns;
        }

        Amortyzacje.Model.evolutionDB _db;
        public Pracownik(string connectionString, string providerName) {

            _db=new Amortyzacje.Model.evolutionDB(connectionString, providerName);
            Init();            
         }
        void Init(){
            TestMode=this._db.DataProvider.ConnectionString.Equals("test", StringComparison.InvariantCultureIgnoreCase);
            _dirtyColumns=new List<IColumn>();
            if(TestMode){
                Pracownik.SetTestRepo();
                _repo=_testRepo;
            }else{
                _repo = new SubSonicRepository<Pracownik>(_db);
            }
            tbl=_repo.GetTable();
            SetIsNew(true);
            OnCreated();       

        }
        
        public Pracownik(){
             _db=new Amortyzacje.Model.evolutionDB();
            Init();            
        }
        
       
        partial void OnCreated();
            
        partial void OnLoaded();
        
        partial void OnSaved();
        
        partial void OnChanged();
        
        public IList<IColumn> Columns{
            get{
                return tbl.Columns;
            }
        }

        public Pracownik(Expression<Func<Pracownik, bool>> expression):this() {

            SetIsLoaded(_repo.Load(this,expression));
        }
        
       
        
        internal static IRepository<Pracownik> GetRepo(string connectionString, string providerName){
            Amortyzacje.Model.evolutionDB db;
            if(String.IsNullOrEmpty(connectionString)){
                db=new Amortyzacje.Model.evolutionDB();
            }else{
                db=new Amortyzacje.Model.evolutionDB(connectionString, providerName);
            }
            IRepository<Pracownik> _repo;
            
            if(db.TestMode){
                Pracownik.SetTestRepo();
                _repo=_testRepo;
            }else{
                _repo = new SubSonicRepository<Pracownik>(db);
            }
            return _repo;        
        }       
        
        internal static IRepository<Pracownik> GetRepo(){
            return GetRepo("","");
        }
        
        public static Pracownik SingleOrDefault(Expression<Func<Pracownik, bool>> expression) {

            var repo = GetRepo();
            var results=repo.Find(expression);
            Pracownik single=null;
            if(results.Count() > 0){
                single=results.ToList()[0];
                single.OnLoaded();
                single.SetIsLoaded(true);
                single.SetIsNew(false);
            }

            return single;
        }      
        
        public static Pracownik SingleOrDefault(Expression<Func<Pracownik, bool>> expression,string connectionString, string providerName) {
            var repo = GetRepo(connectionString,providerName);
            var results=repo.Find(expression);
            Pracownik single=null;
            if(results.Count() > 0){
                single=results.ToList()[0];
            }

            return single;


        }
        
        
        public static bool Exists(Expression<Func<Pracownik, bool>> expression,string connectionString, string providerName) {
           
            return All(connectionString,providerName).Any(expression);
        }        
        public static bool Exists(Expression<Func<Pracownik, bool>> expression) {
           
            return All().Any(expression);
        }        

        public static IList<Pracownik> Find(Expression<Func<Pracownik, bool>> expression) {
            
            var repo = GetRepo();
            return repo.Find(expression).ToList();
        }
        
        public static IList<Pracownik> Find(Expression<Func<Pracownik, bool>> expression,string connectionString, string providerName) {

            var repo = GetRepo(connectionString,providerName);
            return repo.Find(expression).ToList();

        }
        public static IQueryable<Pracownik> All(string connectionString, string providerName) {
            return GetRepo(connectionString,providerName).GetAll();
        }
        public static IQueryable<Pracownik> All() {
            return GetRepo().GetAll();
        }
        
        public static PagedList<Pracownik> GetPaged(string sortBy, int pageIndex, int pageSize,string connectionString, string providerName) {
            return GetRepo(connectionString,providerName).GetPaged(sortBy, pageIndex, pageSize);
        }
      
        public static PagedList<Pracownik> GetPaged(string sortBy, int pageIndex, int pageSize) {
            return GetRepo().GetPaged(sortBy, pageIndex, pageSize);
        }

        public static PagedList<Pracownik> GetPaged(int pageIndex, int pageSize,string connectionString, string providerName) {
            return GetRepo(connectionString,providerName).GetPaged(pageIndex, pageSize);
            
        }


        public static PagedList<Pracownik> GetPaged(int pageIndex, int pageSize) {
            return GetRepo().GetPaged(pageIndex, pageSize);
            
        }

        public string KeyName()
        {
            return "id_prac";
        }

        public object KeyValue()
        {
            return this.id_prac;
        }
        
        public void SetKeyValue(object value) {
            if (value != null && value!=DBNull.Value) {
                var settable = value.ChangeTypeTo<int>();
                this.GetType().GetProperty(this.KeyName()).SetValue(this, settable, null);
            }
        }
        
        public override string ToString(){
                            return this.nazwisko.ToString();
                    }

        public override bool Equals(object obj){
            if(obj.GetType()==typeof(Pracownik)){
                Pracownik compare=(Pracownik)obj;
                return compare.KeyValue()==this.KeyValue();
            }else{
                return base.Equals(obj);
            }
        }

        
        public override int GetHashCode() {
            return this.id_prac;
        }
        
        public string DescriptorValue()
        {
                            return this.nazwisko.ToString();
                    }

        public string DescriptorColumn() {
            return "nazwisko";
        }
        public static string GetKeyColumn()
        {
            return "id_prac";
        }        
        public static string GetDescriptorColumn()
        {
            return "nazwisko";
        }
        
        #region ' Foreign Keys '
        #endregion
        

        int _id_prac;
        public int id_prac
        {
            get { return _id_prac; }
            set
            {
                if(_id_prac!=value){
                    _id_prac=value;
                    var col=tbl.Columns.SingleOrDefault(x=>x.Name=="id_prac");
                    if(col!=null){
                        if(!_dirtyColumns.Any(x=>x.Name==col.Name) && _isLoaded){
                            _dirtyColumns.Add(col);
                        }
                    }
                    OnChanged();
                }
            }
        }

        int? _nrAkt;
        public int? nrAkt
        {
            get { return _nrAkt; }
            set
            {
                if(_nrAkt!=value){
                    _nrAkt=value;
                    var col=tbl.Columns.SingleOrDefault(x=>x.Name=="nrAkt");
                    if(col!=null){
                        if(!_dirtyColumns.Any(x=>x.Name==col.Name) && _isLoaded){
                            _dirtyColumns.Add(col);
                        }
                    }
                    OnChanged();
                }
            }
        }

        string _nazwisko;
        public string nazwisko
        {
            get { return _nazwisko; }
            set
            {
                if(_nazwisko!=value){
                    _nazwisko=value;
                    var col=tbl.Columns.SingleOrDefault(x=>x.Name=="nazwisko");
                    if(col!=null){
                        if(!_dirtyColumns.Any(x=>x.Name==col.Name) && _isLoaded){
                            _dirtyColumns.Add(col);
                        }
                    }
                    OnChanged();
                }
            }
        }

        string _imie;
        public string imie
        {
            get { return _imie; }
            set
            {
                if(_imie!=value){
                    _imie=value;
                    var col=tbl.Columns.SingleOrDefault(x=>x.Name=="imie");
                    if(col!=null){
                        if(!_dirtyColumns.Any(x=>x.Name==col.Name) && _isLoaded){
                            _dirtyColumns.Add(col);
                        }
                    }
                    OnChanged();
                }
            }
        }

        string _imie2;
        public string imie2
        {
            get { return _imie2; }
            set
            {
                if(_imie2!=value){
                    _imie2=value;
                    var col=tbl.Columns.SingleOrDefault(x=>x.Name=="imie2");
                    if(col!=null){
                        if(!_dirtyColumns.Any(x=>x.Name==col.Name) && _isLoaded){
                            _dirtyColumns.Add(col);
                        }
                    }
                    OnChanged();
                }
            }
        }

        string _plec;
        public string plec
        {
            get { return _plec; }
            set
            {
                if(_plec!=value){
                    _plec=value;
                    var col=tbl.Columns.SingleOrDefault(x=>x.Name=="plec");
                    if(col!=null){
                        if(!_dirtyColumns.Any(x=>x.Name==col.Name) && _isLoaded){
                            _dirtyColumns.Add(col);
                        }
                    }
                    OnChanged();
                }
            }
        }

        string _dataUrodzenia;
        public string dataUrodzenia
        {
            get { return _dataUrodzenia; }
            set
            {
                if(_dataUrodzenia!=value){
                    _dataUrodzenia=value;
                    var col=tbl.Columns.SingleOrDefault(x=>x.Name=="dataUrodzenia");
                    if(col!=null){
                        if(!_dirtyColumns.Any(x=>x.Name==col.Name) && _isLoaded){
                            _dirtyColumns.Add(col);
                        }
                    }
                    OnChanged();
                }
            }
        }

        string _miejsceUrodzenia;
        public string miejsceUrodzenia
        {
            get { return _miejsceUrodzenia; }
            set
            {
                if(_miejsceUrodzenia!=value){
                    _miejsceUrodzenia=value;
                    var col=tbl.Columns.SingleOrDefault(x=>x.Name=="miejsceUrodzenia");
                    if(col!=null){
                        if(!_dirtyColumns.Any(x=>x.Name==col.Name) && _isLoaded){
                            _dirtyColumns.Add(col);
                        }
                    }
                    OnChanged();
                }
            }
        }

        string _imieOjca;
        public string imieOjca
        {
            get { return _imieOjca; }
            set
            {
                if(_imieOjca!=value){
                    _imieOjca=value;
                    var col=tbl.Columns.SingleOrDefault(x=>x.Name=="imieOjca");
                    if(col!=null){
                        if(!_dirtyColumns.Any(x=>x.Name==col.Name) && _isLoaded){
                            _dirtyColumns.Add(col);
                        }
                    }
                    OnChanged();
                }
            }
        }

        string _imieMatki;
        public string imieMatki
        {
            get { return _imieMatki; }
            set
            {
                if(_imieMatki!=value){
                    _imieMatki=value;
                    var col=tbl.Columns.SingleOrDefault(x=>x.Name=="imieMatki");
                    if(col!=null){
                        if(!_dirtyColumns.Any(x=>x.Name==col.Name) && _isLoaded){
                            _dirtyColumns.Add(col);
                        }
                    }
                    OnChanged();
                }
            }
        }

        string _nazwiskoRodowe;
        public string nazwiskoRodowe
        {
            get { return _nazwiskoRodowe; }
            set
            {
                if(_nazwiskoRodowe!=value){
                    _nazwiskoRodowe=value;
                    var col=tbl.Columns.SingleOrDefault(x=>x.Name=="nazwiskoRodowe");
                    if(col!=null){
                        if(!_dirtyColumns.Any(x=>x.Name==col.Name) && _isLoaded){
                            _dirtyColumns.Add(col);
                        }
                    }
                    OnChanged();
                }
            }
        }

        string _nazwiskoRodoweMatki;
        public string nazwiskoRodoweMatki
        {
            get { return _nazwiskoRodoweMatki; }
            set
            {
                if(_nazwiskoRodoweMatki!=value){
                    _nazwiskoRodoweMatki=value;
                    var col=tbl.Columns.SingleOrDefault(x=>x.Name=="nazwiskoRodoweMatki");
                    if(col!=null){
                        if(!_dirtyColumns.Any(x=>x.Name==col.Name) && _isLoaded){
                            _dirtyColumns.Add(col);
                        }
                    }
                    OnChanged();
                }
            }
        }

        string _nrPesel;
        public string nrPesel
        {
            get { return _nrPesel; }
            set
            {
                if(_nrPesel!=value){
                    _nrPesel=value;
                    var col=tbl.Columns.SingleOrDefault(x=>x.Name=="nrPesel");
                    if(col!=null){
                        if(!_dirtyColumns.Any(x=>x.Name==col.Name) && _isLoaded){
                            _dirtyColumns.Add(col);
                        }
                    }
                    OnChanged();
                }
            }
        }

        string _nrNip;
        public string nrNip
        {
            get { return _nrNip; }
            set
            {
                if(_nrNip!=value){
                    _nrNip=value;
                    var col=tbl.Columns.SingleOrDefault(x=>x.Name=="nrNip");
                    if(col!=null){
                        if(!_dirtyColumns.Any(x=>x.Name==col.Name) && _isLoaded){
                            _dirtyColumns.Add(col);
                        }
                    }
                    OnChanged();
                }
            }
        }

        string _stanCywilny;
        public string stanCywilny
        {
            get { return _stanCywilny; }
            set
            {
                if(_stanCywilny!=value){
                    _stanCywilny=value;
                    var col=tbl.Columns.SingleOrDefault(x=>x.Name=="stanCywilny");
                    if(col!=null){
                        if(!_dirtyColumns.Any(x=>x.Name==col.Name) && _isLoaded){
                            _dirtyColumns.Add(col);
                        }
                    }
                    OnChanged();
                }
            }
        }

        string _telefon;
        public string telefon
        {
            get { return _telefon; }
            set
            {
                if(_telefon!=value){
                    _telefon=value;
                    var col=tbl.Columns.SingleOrDefault(x=>x.Name=="telefon");
                    if(col!=null){
                        if(!_dirtyColumns.Any(x=>x.Name==col.Name) && _isLoaded){
                            _dirtyColumns.Add(col);
                        }
                    }
                    OnChanged();
                }
            }
        }

        string _seriaInumerDowoduOsobistego;
        public string seriaInumerDowoduOsobistego
        {
            get { return _seriaInumerDowoduOsobistego; }
            set
            {
                if(_seriaInumerDowoduOsobistego!=value){
                    _seriaInumerDowoduOsobistego=value;
                    var col=tbl.Columns.SingleOrDefault(x=>x.Name=="seriaInumerDowoduOsobistego");
                    if(col!=null){
                        if(!_dirtyColumns.Any(x=>x.Name==col.Name) && _isLoaded){
                            _dirtyColumns.Add(col);
                        }
                    }
                    OnChanged();
                }
            }
        }

        string _dataWydaniaDowoduOsobistego;
        public string dataWydaniaDowoduOsobistego
        {
            get { return _dataWydaniaDowoduOsobistego; }
            set
            {
                if(_dataWydaniaDowoduOsobistego!=value){
                    _dataWydaniaDowoduOsobistego=value;
                    var col=tbl.Columns.SingleOrDefault(x=>x.Name=="dataWydaniaDowoduOsobistego");
                    if(col!=null){
                        if(!_dirtyColumns.Any(x=>x.Name==col.Name) && _isLoaded){
                            _dirtyColumns.Add(col);
                        }
                    }
                    OnChanged();
                }
            }
        }

        string _wydanyPrzezDowodOsobisty;
        public string wydanyPrzezDowodOsobisty
        {
            get { return _wydanyPrzezDowodOsobisty; }
            set
            {
                if(_wydanyPrzezDowodOsobisty!=value){
                    _wydanyPrzezDowodOsobisty=value;
                    var col=tbl.Columns.SingleOrDefault(x=>x.Name=="wydanyPrzezDowodOsobisty");
                    if(col!=null){
                        if(!_dirtyColumns.Any(x=>x.Name==col.Name) && _isLoaded){
                            _dirtyColumns.Add(col);
                        }
                    }
                    OnChanged();
                }
            }
        }

        string _wyksztalcenie;
        public string wyksztalcenie
        {
            get { return _wyksztalcenie; }
            set
            {
                if(_wyksztalcenie!=value){
                    _wyksztalcenie=value;
                    var col=tbl.Columns.SingleOrDefault(x=>x.Name=="wyksztalcenie");
                    if(col!=null){
                        if(!_dirtyColumns.Any(x=>x.Name==col.Name) && _isLoaded){
                            _dirtyColumns.Add(col);
                        }
                    }
                    OnChanged();
                }
            }
        }

        string _nrKonta;
        public string nrKonta
        {
            get { return _nrKonta; }
            set
            {
                if(_nrKonta!=value){
                    _nrKonta=value;
                    var col=tbl.Columns.SingleOrDefault(x=>x.Name=="nrKonta");
                    if(col!=null){
                        if(!_dirtyColumns.Any(x=>x.Name==col.Name) && _isLoaded){
                            _dirtyColumns.Add(col);
                        }
                    }
                    OnChanged();
                }
            }
        }

        int? _wykorzystaneDniUrlopuStandardowego;
        public int? wykorzystaneDniUrlopuStandardowego
        {
            get { return _wykorzystaneDniUrlopuStandardowego; }
            set
            {
                if(_wykorzystaneDniUrlopuStandardowego!=value){
                    _wykorzystaneDniUrlopuStandardowego=value;
                    var col=tbl.Columns.SingleOrDefault(x=>x.Name=="wykorzystaneDniUrlopuStandardowego");
                    if(col!=null){
                        if(!_dirtyColumns.Any(x=>x.Name==col.Name) && _isLoaded){
                            _dirtyColumns.Add(col);
                        }
                    }
                    OnChanged();
                }
            }
        }

        int? _wykorzystaneDniUrlopuChorobowego;
        public int? wykorzystaneDniUrlopuChorobowego
        {
            get { return _wykorzystaneDniUrlopuChorobowego; }
            set
            {
                if(_wykorzystaneDniUrlopuChorobowego!=value){
                    _wykorzystaneDniUrlopuChorobowego=value;
                    var col=tbl.Columns.SingleOrDefault(x=>x.Name=="wykorzystaneDniUrlopuChorobowego");
                    if(col!=null){
                        if(!_dirtyColumns.Any(x=>x.Name==col.Name) && _isLoaded){
                            _dirtyColumns.Add(col);
                        }
                    }
                    OnChanged();
                }
            }
        }

        int? _wykorzystaneDniUrlopuMacierzynskiego;
        public int? wykorzystaneDniUrlopuMacierzynskiego
        {
            get { return _wykorzystaneDniUrlopuMacierzynskiego; }
            set
            {
                if(_wykorzystaneDniUrlopuMacierzynskiego!=value){
                    _wykorzystaneDniUrlopuMacierzynskiego=value;
                    var col=tbl.Columns.SingleOrDefault(x=>x.Name=="wykorzystaneDniUrlopuMacierzynskiego");
                    if(col!=null){
                        if(!_dirtyColumns.Any(x=>x.Name==col.Name) && _isLoaded){
                            _dirtyColumns.Add(col);
                        }
                    }
                    OnChanged();
                }
            }
        }

        int? _wykorzystaneDniUrlopuOkolicznosciowego;
        public int? wykorzystaneDniUrlopuOkolicznosciowego
        {
            get { return _wykorzystaneDniUrlopuOkolicznosciowego; }
            set
            {
                if(_wykorzystaneDniUrlopuOkolicznosciowego!=value){
                    _wykorzystaneDniUrlopuOkolicznosciowego=value;
                    var col=tbl.Columns.SingleOrDefault(x=>x.Name=="wykorzystaneDniUrlopuOkolicznosciowego");
                    if(col!=null){
                        if(!_dirtyColumns.Any(x=>x.Name==col.Name) && _isLoaded){
                            _dirtyColumns.Add(col);
                        }
                    }
                    OnChanged();
                }
            }
        }

        string _login;
        public string login
        {
            get { return _login; }
            set
            {
                if(_login!=value){
                    _login=value;
                    var col=tbl.Columns.SingleOrDefault(x=>x.Name=="login");
                    if(col!=null){
                        if(!_dirtyColumns.Any(x=>x.Name==col.Name) && _isLoaded){
                            _dirtyColumns.Add(col);
                        }
                    }
                    OnChanged();
                }
            }
        }

        string _haslo;
        public string haslo
        {
            get { return _haslo; }
            set
            {
                if(_haslo!=value){
                    _haslo=value;
                    var col=tbl.Columns.SingleOrDefault(x=>x.Name=="haslo");
                    if(col!=null){
                        if(!_dirtyColumns.Any(x=>x.Name==col.Name) && _isLoaded){
                            _dirtyColumns.Add(col);
                        }
                    }
                    OnChanged();
                }
            }
        }

        string _specjalizacja;
        public string specjalizacja
        {
            get { return _specjalizacja; }
            set
            {
                if(_specjalizacja!=value){
                    _specjalizacja=value;
                    var col=tbl.Columns.SingleOrDefault(x=>x.Name=="specjalizacja");
                    if(col!=null){
                        if(!_dirtyColumns.Any(x=>x.Name==col.Name) && _isLoaded){
                            _dirtyColumns.Add(col);
                        }
                    }
                    OnChanged();
                }
            }
        }



        public DbCommand GetUpdateCommand() {
            if(TestMode)
                return _db.DataProvider.CreateCommand();
            else
                return this.ToUpdateQuery(_db.Provider).GetCommand().ToDbCommand();
            
        }
        public DbCommand GetInsertCommand() {
 
            if(TestMode)
                return _db.DataProvider.CreateCommand();
            else
                return this.ToInsertQuery(_db.Provider).GetCommand().ToDbCommand();
        }
        
        public DbCommand GetDeleteCommand() {
            if(TestMode)
                return _db.DataProvider.CreateCommand();
            else
                return this.ToDeleteQuery(_db.Provider).GetCommand().ToDbCommand();
        }
       
        
        public void Update(){
            Update(_db.DataProvider);
        }
        
        public void Update(IDataProvider provider){
        
            
            if(this._dirtyColumns.Count>0){
                _repo.Update(this,provider);
                _dirtyColumns.Clear();    
            }
            OnSaved();
       }
 
        public void Add(){
            Add(_db.DataProvider);
        }
        
        
       
        public void Add(IDataProvider provider){

            
            var key=KeyValue();
            if(key==null){
                var newKey=_repo.Add(this,provider);
                this.SetKeyValue(newKey);
            }else{
                _repo.Add(this,provider);
            }
            SetIsNew(false);
            OnSaved();
        }
        
                
        
        public void Save() {
            Save(_db.DataProvider);
        }      
        public void Save(IDataProvider provider) {
            
           
            if (_isNew) {
                Add(provider);
                
            } else {
                Update(provider);
            }
            
        }

        

        public void Delete(IDataProvider provider) {
                   
                 
            _repo.Delete(KeyValue());
            
                    }


        public void Delete() {
            Delete(_db.DataProvider);
        }


        public static void Delete(Expression<Func<Pracownik, bool>> expression) {
            var repo = GetRepo();
            
       
            
            repo.DeleteMany(expression);
            
        }

        

        public void Load(IDataReader rdr) {
            Load(rdr, true);
        }
        public void Load(IDataReader rdr, bool closeReader) {
            if (rdr.Read()) {

                try {
                    rdr.Load(this);
                    SetIsNew(false);
                    SetIsLoaded(true);
                } catch {
                    SetIsLoaded(false);
                    throw;
                }
            }else{
                SetIsLoaded(false);
            }

            if (closeReader)
                rdr.Dispose();
        }
        

    } 
    
    
    /// <summary>
    /// A class which represents the Prelegenci table in the evolution Database.
    /// </summary>
    public partial class Prelegenci: IActiveRecord
    {
    
        #region Built-in testing
        static TestRepository<Prelegenci> _testRepo;
        

        
        static void SetTestRepo(){
            _testRepo = _testRepo ?? new TestRepository<Prelegenci>(new Amortyzacje.Model.evolutionDB());
        }
        public static void ResetTestRepo(){
            _testRepo = null;
            SetTestRepo();
        }
        public static void Setup(List<Prelegenci> testlist){
            SetTestRepo();
            foreach (var item in testlist)
            {
                _testRepo._items.Add(item);
            }
        }
        public static void Setup(Prelegenci item) {
            SetTestRepo();
            _testRepo._items.Add(item);
        }
        public static void Setup(int testItems) {
            SetTestRepo();
            for(int i=0;i<testItems;i++){
                Prelegenci item=new Prelegenci();
                _testRepo._items.Add(item);
            }
        }
        
        public bool TestMode = false;


        #endregion

        IRepository<Prelegenci> _repo;
        ITable tbl;
        bool _isNew;
        public bool IsNew(){
            return _isNew;
        }
        
        public void SetIsLoaded(bool isLoaded){
            _isLoaded=isLoaded;
            if(isLoaded)
                OnLoaded();
        }
        
        public void SetIsNew(bool isNew){
            _isNew=isNew;
        }
        bool _isLoaded;
        public bool IsLoaded(){
            return _isLoaded;
        }
                
        List<IColumn> _dirtyColumns;
        public bool IsDirty(){
            return _dirtyColumns.Count>0;
        }
        
        public List<IColumn> GetDirtyColumns (){
            return _dirtyColumns;
        }

        Amortyzacje.Model.evolutionDB _db;
        public Prelegenci(string connectionString, string providerName) {

            _db=new Amortyzacje.Model.evolutionDB(connectionString, providerName);
            Init();            
         }
        void Init(){
            TestMode=this._db.DataProvider.ConnectionString.Equals("test", StringComparison.InvariantCultureIgnoreCase);
            _dirtyColumns=new List<IColumn>();
            if(TestMode){
                Prelegenci.SetTestRepo();
                _repo=_testRepo;
            }else{
                _repo = new SubSonicRepository<Prelegenci>(_db);
            }
            tbl=_repo.GetTable();
            SetIsNew(true);
            OnCreated();       

        }
        
        public Prelegenci(){
             _db=new Amortyzacje.Model.evolutionDB();
            Init();            
        }
        
       
        partial void OnCreated();
            
        partial void OnLoaded();
        
        partial void OnSaved();
        
        partial void OnChanged();
        
        public IList<IColumn> Columns{
            get{
                return tbl.Columns;
            }
        }

        public Prelegenci(Expression<Func<Prelegenci, bool>> expression):this() {

            SetIsLoaded(_repo.Load(this,expression));
        }
        
       
        
        internal static IRepository<Prelegenci> GetRepo(string connectionString, string providerName){
            Amortyzacje.Model.evolutionDB db;
            if(String.IsNullOrEmpty(connectionString)){
                db=new Amortyzacje.Model.evolutionDB();
            }else{
                db=new Amortyzacje.Model.evolutionDB(connectionString, providerName);
            }
            IRepository<Prelegenci> _repo;
            
            if(db.TestMode){
                Prelegenci.SetTestRepo();
                _repo=_testRepo;
            }else{
                _repo = new SubSonicRepository<Prelegenci>(db);
            }
            return _repo;        
        }       
        
        internal static IRepository<Prelegenci> GetRepo(){
            return GetRepo("","");
        }
        
        public static Prelegenci SingleOrDefault(Expression<Func<Prelegenci, bool>> expression) {

            var repo = GetRepo();
            var results=repo.Find(expression);
            Prelegenci single=null;
            if(results.Count() > 0){
                single=results.ToList()[0];
                single.OnLoaded();
                single.SetIsLoaded(true);
                single.SetIsNew(false);
            }

            return single;
        }      
        
        public static Prelegenci SingleOrDefault(Expression<Func<Prelegenci, bool>> expression,string connectionString, string providerName) {
            var repo = GetRepo(connectionString,providerName);
            var results=repo.Find(expression);
            Prelegenci single=null;
            if(results.Count() > 0){
                single=results.ToList()[0];
            }

            return single;


        }
        
        
        public static bool Exists(Expression<Func<Prelegenci, bool>> expression,string connectionString, string providerName) {
           
            return All(connectionString,providerName).Any(expression);
        }        
        public static bool Exists(Expression<Func<Prelegenci, bool>> expression) {
           
            return All().Any(expression);
        }        

        public static IList<Prelegenci> Find(Expression<Func<Prelegenci, bool>> expression) {
            
            var repo = GetRepo();
            return repo.Find(expression).ToList();
        }
        
        public static IList<Prelegenci> Find(Expression<Func<Prelegenci, bool>> expression,string connectionString, string providerName) {

            var repo = GetRepo(connectionString,providerName);
            return repo.Find(expression).ToList();

        }
        public static IQueryable<Prelegenci> All(string connectionString, string providerName) {
            return GetRepo(connectionString,providerName).GetAll();
        }
        public static IQueryable<Prelegenci> All() {
            return GetRepo().GetAll();
        }
        
        public static PagedList<Prelegenci> GetPaged(string sortBy, int pageIndex, int pageSize,string connectionString, string providerName) {
            return GetRepo(connectionString,providerName).GetPaged(sortBy, pageIndex, pageSize);
        }
      
        public static PagedList<Prelegenci> GetPaged(string sortBy, int pageIndex, int pageSize) {
            return GetRepo().GetPaged(sortBy, pageIndex, pageSize);
        }

        public static PagedList<Prelegenci> GetPaged(int pageIndex, int pageSize,string connectionString, string providerName) {
            return GetRepo(connectionString,providerName).GetPaged(pageIndex, pageSize);
            
        }


        public static PagedList<Prelegenci> GetPaged(int pageIndex, int pageSize) {
            return GetRepo().GetPaged(pageIndex, pageSize);
            
        }

        public string KeyName()
        {
            return "pesel";
        }

        public object KeyValue()
        {
            return this.pesel;
        }
        
        public void SetKeyValue(object value) {
            if (value != null && value!=DBNull.Value) {
                var settable = value.ChangeTypeTo<long>();
                this.GetType().GetProperty(this.KeyName()).SetValue(this, settable, null);
            }
        }
        
        public override string ToString(){
                            return this.imie.ToString();
                    }

        public override bool Equals(object obj){
            if(obj.GetType()==typeof(Prelegenci)){
                Prelegenci compare=(Prelegenci)obj;
                return compare.KeyValue()==this.KeyValue();
            }else{
                return base.Equals(obj);
            }
        }

        public string DescriptorValue()
        {
                            return this.imie.ToString();
                    }

        public string DescriptorColumn() {
            return "imie";
        }
        public static string GetKeyColumn()
        {
            return "pesel";
        }        
        public static string GetDescriptorColumn()
        {
            return "imie";
        }
        
        #region ' Foreign Keys '
        #endregion
        

        long _pesel;
        public long pesel
        {
            get { return _pesel; }
            set
            {
                if(_pesel!=value){
                    _pesel=value;
                    var col=tbl.Columns.SingleOrDefault(x=>x.Name=="pesel");
                    if(col!=null){
                        if(!_dirtyColumns.Any(x=>x.Name==col.Name) && _isLoaded){
                            _dirtyColumns.Add(col);
                        }
                    }
                    OnChanged();
                }
            }
        }

        string _imie;
        public string imie
        {
            get { return _imie; }
            set
            {
                if(_imie!=value){
                    _imie=value;
                    var col=tbl.Columns.SingleOrDefault(x=>x.Name=="imie");
                    if(col!=null){
                        if(!_dirtyColumns.Any(x=>x.Name==col.Name) && _isLoaded){
                            _dirtyColumns.Add(col);
                        }
                    }
                    OnChanged();
                }
            }
        }

        sbyte _umowa;
        public sbyte umowa
        {
            get { return _umowa; }
            set
            {
                if(_umowa!=value){
                    _umowa=value;
                    var col=tbl.Columns.SingleOrDefault(x=>x.Name=="umowa");
                    if(col!=null){
                        if(!_dirtyColumns.Any(x=>x.Name==col.Name) && _isLoaded){
                            _dirtyColumns.Add(col);
                        }
                    }
                    OnChanged();
                }
            }
        }

        string _nazwisko;
        public string nazwisko
        {
            get { return _nazwisko; }
            set
            {
                if(_nazwisko!=value){
                    _nazwisko=value;
                    var col=tbl.Columns.SingleOrDefault(x=>x.Name=="nazwisko");
                    if(col!=null){
                        if(!_dirtyColumns.Any(x=>x.Name==col.Name) && _isLoaded){
                            _dirtyColumns.Add(col);
                        }
                    }
                    OnChanged();
                }
            }
        }



        public DbCommand GetUpdateCommand() {
            if(TestMode)
                return _db.DataProvider.CreateCommand();
            else
                return this.ToUpdateQuery(_db.Provider).GetCommand().ToDbCommand();
            
        }
        public DbCommand GetInsertCommand() {
 
            if(TestMode)
                return _db.DataProvider.CreateCommand();
            else
                return this.ToInsertQuery(_db.Provider).GetCommand().ToDbCommand();
        }
        
        public DbCommand GetDeleteCommand() {
            if(TestMode)
                return _db.DataProvider.CreateCommand();
            else
                return this.ToDeleteQuery(_db.Provider).GetCommand().ToDbCommand();
        }
       
        
        public void Update(){
            Update(_db.DataProvider);
        }
        
        public void Update(IDataProvider provider){
        
            
            if(this._dirtyColumns.Count>0){
                _repo.Update(this,provider);
                _dirtyColumns.Clear();    
            }
            OnSaved();
       }
 
        public void Add(){
            Add(_db.DataProvider);
        }
        
        
       
        public void Add(IDataProvider provider){

            
            var key=KeyValue();
            if(key==null){
                var newKey=_repo.Add(this,provider);
                this.SetKeyValue(newKey);
            }else{
                _repo.Add(this,provider);
            }
            SetIsNew(false);
            OnSaved();
        }
        
                
        
        public void Save() {
            Save(_db.DataProvider);
        }      
        public void Save(IDataProvider provider) {
            
           
            if (_isNew) {
                Add(provider);
                
            } else {
                Update(provider);
            }
            
        }

        

        public void Delete(IDataProvider provider) {
                   
                 
            _repo.Delete(KeyValue());
            
                    }


        public void Delete() {
            Delete(_db.DataProvider);
        }


        public static void Delete(Expression<Func<Prelegenci, bool>> expression) {
            var repo = GetRepo();
            
       
            
            repo.DeleteMany(expression);
            
        }

        

        public void Load(IDataReader rdr) {
            Load(rdr, true);
        }
        public void Load(IDataReader rdr, bool closeReader) {
            if (rdr.Read()) {

                try {
                    rdr.Load(this);
                    SetIsNew(false);
                    SetIsLoaded(true);
                } catch {
                    SetIsLoaded(false);
                    throw;
                }
            }else{
                SetIsLoaded(false);
            }

            if (closeReader)
                rdr.Dispose();
        }
        

    } 
    
    
    /// <summary>
    /// A class which represents the Rodzina table in the evolution Database.
    /// </summary>
    public partial class Rodzina: IActiveRecord
    {
    
        #region Built-in testing
        static TestRepository<Rodzina> _testRepo;
        

        
        static void SetTestRepo(){
            _testRepo = _testRepo ?? new TestRepository<Rodzina>(new Amortyzacje.Model.evolutionDB());
        }
        public static void ResetTestRepo(){
            _testRepo = null;
            SetTestRepo();
        }
        public static void Setup(List<Rodzina> testlist){
            SetTestRepo();
            foreach (var item in testlist)
            {
                _testRepo._items.Add(item);
            }
        }
        public static void Setup(Rodzina item) {
            SetTestRepo();
            _testRepo._items.Add(item);
        }
        public static void Setup(int testItems) {
            SetTestRepo();
            for(int i=0;i<testItems;i++){
                Rodzina item=new Rodzina();
                _testRepo._items.Add(item);
            }
        }
        
        public bool TestMode = false;


        #endregion

        IRepository<Rodzina> _repo;
        ITable tbl;
        bool _isNew;
        public bool IsNew(){
            return _isNew;
        }
        
        public void SetIsLoaded(bool isLoaded){
            _isLoaded=isLoaded;
            if(isLoaded)
                OnLoaded();
        }
        
        public void SetIsNew(bool isNew){
            _isNew=isNew;
        }
        bool _isLoaded;
        public bool IsLoaded(){
            return _isLoaded;
        }
                
        List<IColumn> _dirtyColumns;
        public bool IsDirty(){
            return _dirtyColumns.Count>0;
        }
        
        public List<IColumn> GetDirtyColumns (){
            return _dirtyColumns;
        }

        Amortyzacje.Model.evolutionDB _db;
        public Rodzina(string connectionString, string providerName) {

            _db=new Amortyzacje.Model.evolutionDB(connectionString, providerName);
            Init();            
         }
        void Init(){
            TestMode=this._db.DataProvider.ConnectionString.Equals("test", StringComparison.InvariantCultureIgnoreCase);
            _dirtyColumns=new List<IColumn>();
            if(TestMode){
                Rodzina.SetTestRepo();
                _repo=_testRepo;
            }else{
                _repo = new SubSonicRepository<Rodzina>(_db);
            }
            tbl=_repo.GetTable();
            SetIsNew(true);
            OnCreated();       

        }
        
        public Rodzina(){
             _db=new Amortyzacje.Model.evolutionDB();
            Init();            
        }
        
       
        partial void OnCreated();
            
        partial void OnLoaded();
        
        partial void OnSaved();
        
        partial void OnChanged();
        
        public IList<IColumn> Columns{
            get{
                return tbl.Columns;
            }
        }

        public Rodzina(Expression<Func<Rodzina, bool>> expression):this() {

            SetIsLoaded(_repo.Load(this,expression));
        }
        
       
        
        internal static IRepository<Rodzina> GetRepo(string connectionString, string providerName){
            Amortyzacje.Model.evolutionDB db;
            if(String.IsNullOrEmpty(connectionString)){
                db=new Amortyzacje.Model.evolutionDB();
            }else{
                db=new Amortyzacje.Model.evolutionDB(connectionString, providerName);
            }
            IRepository<Rodzina> _repo;
            
            if(db.TestMode){
                Rodzina.SetTestRepo();
                _repo=_testRepo;
            }else{
                _repo = new SubSonicRepository<Rodzina>(db);
            }
            return _repo;        
        }       
        
        internal static IRepository<Rodzina> GetRepo(){
            return GetRepo("","");
        }
        
        public static Rodzina SingleOrDefault(Expression<Func<Rodzina, bool>> expression) {

            var repo = GetRepo();
            var results=repo.Find(expression);
            Rodzina single=null;
            if(results.Count() > 0){
                single=results.ToList()[0];
                single.OnLoaded();
                single.SetIsLoaded(true);
                single.SetIsNew(false);
            }

            return single;
        }      
        
        public static Rodzina SingleOrDefault(Expression<Func<Rodzina, bool>> expression,string connectionString, string providerName) {
            var repo = GetRepo(connectionString,providerName);
            var results=repo.Find(expression);
            Rodzina single=null;
            if(results.Count() > 0){
                single=results.ToList()[0];
            }

            return single;


        }
        
        
        public static bool Exists(Expression<Func<Rodzina, bool>> expression,string connectionString, string providerName) {
           
            return All(connectionString,providerName).Any(expression);
        }        
        public static bool Exists(Expression<Func<Rodzina, bool>> expression) {
           
            return All().Any(expression);
        }        

        public static IList<Rodzina> Find(Expression<Func<Rodzina, bool>> expression) {
            
            var repo = GetRepo();
            return repo.Find(expression).ToList();
        }
        
        public static IList<Rodzina> Find(Expression<Func<Rodzina, bool>> expression,string connectionString, string providerName) {

            var repo = GetRepo(connectionString,providerName);
            return repo.Find(expression).ToList();

        }
        public static IQueryable<Rodzina> All(string connectionString, string providerName) {
            return GetRepo(connectionString,providerName).GetAll();
        }
        public static IQueryable<Rodzina> All() {
            return GetRepo().GetAll();
        }
        
        public static PagedList<Rodzina> GetPaged(string sortBy, int pageIndex, int pageSize,string connectionString, string providerName) {
            return GetRepo(connectionString,providerName).GetPaged(sortBy, pageIndex, pageSize);
        }
      
        public static PagedList<Rodzina> GetPaged(string sortBy, int pageIndex, int pageSize) {
            return GetRepo().GetPaged(sortBy, pageIndex, pageSize);
        }

        public static PagedList<Rodzina> GetPaged(int pageIndex, int pageSize,string connectionString, string providerName) {
            return GetRepo(connectionString,providerName).GetPaged(pageIndex, pageSize);
            
        }


        public static PagedList<Rodzina> GetPaged(int pageIndex, int pageSize) {
            return GetRepo().GetPaged(pageIndex, pageSize);
            
        }

        public string KeyName()
        {
            return "id";
        }

        public object KeyValue()
        {
            return this.id;
        }
        
        public void SetKeyValue(object value) {
            if (value != null && value!=DBNull.Value) {
                var settable = value.ChangeTypeTo<int>();
                this.GetType().GetProperty(this.KeyName()).SetValue(this, settable, null);
            }
        }
        
        public override string ToString(){
                            return this.nazwiskoMalzonka.ToString();
                    }

        public override bool Equals(object obj){
            if(obj.GetType()==typeof(Rodzina)){
                Rodzina compare=(Rodzina)obj;
                return compare.KeyValue()==this.KeyValue();
            }else{
                return base.Equals(obj);
            }
        }

        
        public override int GetHashCode() {
            return this.id;
        }
        
        public string DescriptorValue()
        {
                            return this.nazwiskoMalzonka.ToString();
                    }

        public string DescriptorColumn() {
            return "nazwiskoMalzonka";
        }
        public static string GetKeyColumn()
        {
            return "id";
        }        
        public static string GetDescriptorColumn()
        {
            return "nazwiskoMalzonka";
        }
        
        #region ' Foreign Keys '
        #endregion
        

        int _id;
        public int id
        {
            get { return _id; }
            set
            {
                if(_id!=value){
                    _id=value;
                    var col=tbl.Columns.SingleOrDefault(x=>x.Name=="id");
                    if(col!=null){
                        if(!_dirtyColumns.Any(x=>x.Name==col.Name) && _isLoaded){
                            _dirtyColumns.Add(col);
                        }
                    }
                    OnChanged();
                }
            }
        }

        int? _id_prac;
        public int? id_prac
        {
            get { return _id_prac; }
            set
            {
                if(_id_prac!=value){
                    _id_prac=value;
                    var col=tbl.Columns.SingleOrDefault(x=>x.Name=="id_prac");
                    if(col!=null){
                        if(!_dirtyColumns.Any(x=>x.Name==col.Name) && _isLoaded){
                            _dirtyColumns.Add(col);
                        }
                    }
                    OnChanged();
                }
            }
        }

        string _nazwiskoMalzonka;
        public string nazwiskoMalzonka
        {
            get { return _nazwiskoMalzonka; }
            set
            {
                if(_nazwiskoMalzonka!=value){
                    _nazwiskoMalzonka=value;
                    var col=tbl.Columns.SingleOrDefault(x=>x.Name=="nazwiskoMalzonka");
                    if(col!=null){
                        if(!_dirtyColumns.Any(x=>x.Name==col.Name) && _isLoaded){
                            _dirtyColumns.Add(col);
                        }
                    }
                    OnChanged();
                }
            }
        }

        string _imieMalzonka;
        public string imieMalzonka
        {
            get { return _imieMalzonka; }
            set
            {
                if(_imieMalzonka!=value){
                    _imieMalzonka=value;
                    var col=tbl.Columns.SingleOrDefault(x=>x.Name=="imieMalzonka");
                    if(col!=null){
                        if(!_dirtyColumns.Any(x=>x.Name==col.Name) && _isLoaded){
                            _dirtyColumns.Add(col);
                        }
                    }
                    OnChanged();
                }
            }
        }

        string _dataUrodzeniaMalzonka;
        public string dataUrodzeniaMalzonka
        {
            get { return _dataUrodzeniaMalzonka; }
            set
            {
                if(_dataUrodzeniaMalzonka!=value){
                    _dataUrodzeniaMalzonka=value;
                    var col=tbl.Columns.SingleOrDefault(x=>x.Name=="dataUrodzeniaMalzonka");
                    if(col!=null){
                        if(!_dirtyColumns.Any(x=>x.Name==col.Name) && _isLoaded){
                            _dirtyColumns.Add(col);
                        }
                    }
                    OnChanged();
                }
            }
        }

        string _nrPeselMalzonka;
        public string nrPeselMalzonka
        {
            get { return _nrPeselMalzonka; }
            set
            {
                if(_nrPeselMalzonka!=value){
                    _nrPeselMalzonka=value;
                    var col=tbl.Columns.SingleOrDefault(x=>x.Name=="nrPeselMalzonka");
                    if(col!=null){
                        if(!_dirtyColumns.Any(x=>x.Name==col.Name) && _isLoaded){
                            _dirtyColumns.Add(col);
                        }
                    }
                    OnChanged();
                }
            }
        }

        string _nrNipMalzonka;
        public string nrNipMalzonka
        {
            get { return _nrNipMalzonka; }
            set
            {
                if(_nrNipMalzonka!=value){
                    _nrNipMalzonka=value;
                    var col=tbl.Columns.SingleOrDefault(x=>x.Name=="nrNipMalzonka");
                    if(col!=null){
                        if(!_dirtyColumns.Any(x=>x.Name==col.Name) && _isLoaded){
                            _dirtyColumns.Add(col);
                        }
                    }
                    OnChanged();
                }
            }
        }



        public DbCommand GetUpdateCommand() {
            if(TestMode)
                return _db.DataProvider.CreateCommand();
            else
                return this.ToUpdateQuery(_db.Provider).GetCommand().ToDbCommand();
            
        }
        public DbCommand GetInsertCommand() {
 
            if(TestMode)
                return _db.DataProvider.CreateCommand();
            else
                return this.ToInsertQuery(_db.Provider).GetCommand().ToDbCommand();
        }
        
        public DbCommand GetDeleteCommand() {
            if(TestMode)
                return _db.DataProvider.CreateCommand();
            else
                return this.ToDeleteQuery(_db.Provider).GetCommand().ToDbCommand();
        }
       
        
        public void Update(){
            Update(_db.DataProvider);
        }
        
        public void Update(IDataProvider provider){
        
            
            if(this._dirtyColumns.Count>0){
                _repo.Update(this,provider);
                _dirtyColumns.Clear();    
            }
            OnSaved();
       }
 
        public void Add(){
            Add(_db.DataProvider);
        }
        
        
       
        public void Add(IDataProvider provider){

            
            var key=KeyValue();
            if(key==null){
                var newKey=_repo.Add(this,provider);
                this.SetKeyValue(newKey);
            }else{
                _repo.Add(this,provider);
            }
            SetIsNew(false);
            OnSaved();
        }
        
                
        
        public void Save() {
            Save(_db.DataProvider);
        }      
        public void Save(IDataProvider provider) {
            
           
            if (_isNew) {
                Add(provider);
                
            } else {
                Update(provider);
            }
            
        }

        

        public void Delete(IDataProvider provider) {
                   
                 
            _repo.Delete(KeyValue());
            
                    }


        public void Delete() {
            Delete(_db.DataProvider);
        }


        public static void Delete(Expression<Func<Rodzina, bool>> expression) {
            var repo = GetRepo();
            
       
            
            repo.DeleteMany(expression);
            
        }

        

        public void Load(IDataReader rdr) {
            Load(rdr, true);
        }
        public void Load(IDataReader rdr, bool closeReader) {
            if (rdr.Read()) {

                try {
                    rdr.Load(this);
                    SetIsNew(false);
                    SetIsLoaded(true);
                } catch {
                    SetIsLoaded(false);
                    throw;
                }
            }else{
                SetIsLoaded(false);
            }

            if (closeReader)
                rdr.Dispose();
        }
        

    } 
    
    
    /// <summary>
    /// A class which represents the Ubezpieczenie table in the evolution Database.
    /// </summary>
    public partial class Ubezpieczenie: IActiveRecord
    {
    
        #region Built-in testing
        static TestRepository<Ubezpieczenie> _testRepo;
        

        
        static void SetTestRepo(){
            _testRepo = _testRepo ?? new TestRepository<Ubezpieczenie>(new Amortyzacje.Model.evolutionDB());
        }
        public static void ResetTestRepo(){
            _testRepo = null;
            SetTestRepo();
        }
        public static void Setup(List<Ubezpieczenie> testlist){
            SetTestRepo();
            foreach (var item in testlist)
            {
                _testRepo._items.Add(item);
            }
        }
        public static void Setup(Ubezpieczenie item) {
            SetTestRepo();
            _testRepo._items.Add(item);
        }
        public static void Setup(int testItems) {
            SetTestRepo();
            for(int i=0;i<testItems;i++){
                Ubezpieczenie item=new Ubezpieczenie();
                _testRepo._items.Add(item);
            }
        }
        
        public bool TestMode = false;


        #endregion

        IRepository<Ubezpieczenie> _repo;
        ITable tbl;
        bool _isNew;
        public bool IsNew(){
            return _isNew;
        }
        
        public void SetIsLoaded(bool isLoaded){
            _isLoaded=isLoaded;
            if(isLoaded)
                OnLoaded();
        }
        
        public void SetIsNew(bool isNew){
            _isNew=isNew;
        }
        bool _isLoaded;
        public bool IsLoaded(){
            return _isLoaded;
        }
                
        List<IColumn> _dirtyColumns;
        public bool IsDirty(){
            return _dirtyColumns.Count>0;
        }
        
        public List<IColumn> GetDirtyColumns (){
            return _dirtyColumns;
        }

        Amortyzacje.Model.evolutionDB _db;
        public Ubezpieczenie(string connectionString, string providerName) {

            _db=new Amortyzacje.Model.evolutionDB(connectionString, providerName);
            Init();            
         }
        void Init(){
            TestMode=this._db.DataProvider.ConnectionString.Equals("test", StringComparison.InvariantCultureIgnoreCase);
            _dirtyColumns=new List<IColumn>();
            if(TestMode){
                Ubezpieczenie.SetTestRepo();
                _repo=_testRepo;
            }else{
                _repo = new SubSonicRepository<Ubezpieczenie>(_db);
            }
            tbl=_repo.GetTable();
            SetIsNew(true);
            OnCreated();       

        }
        
        public Ubezpieczenie(){
             _db=new Amortyzacje.Model.evolutionDB();
            Init();            
        }
        
       
        partial void OnCreated();
            
        partial void OnLoaded();
        
        partial void OnSaved();
        
        partial void OnChanged();
        
        public IList<IColumn> Columns{
            get{
                return tbl.Columns;
            }
        }

        public Ubezpieczenie(Expression<Func<Ubezpieczenie, bool>> expression):this() {

            SetIsLoaded(_repo.Load(this,expression));
        }
        
       
        
        internal static IRepository<Ubezpieczenie> GetRepo(string connectionString, string providerName){
            Amortyzacje.Model.evolutionDB db;
            if(String.IsNullOrEmpty(connectionString)){
                db=new Amortyzacje.Model.evolutionDB();
            }else{
                db=new Amortyzacje.Model.evolutionDB(connectionString, providerName);
            }
            IRepository<Ubezpieczenie> _repo;
            
            if(db.TestMode){
                Ubezpieczenie.SetTestRepo();
                _repo=_testRepo;
            }else{
                _repo = new SubSonicRepository<Ubezpieczenie>(db);
            }
            return _repo;        
        }       
        
        internal static IRepository<Ubezpieczenie> GetRepo(){
            return GetRepo("","");
        }
        
        public static Ubezpieczenie SingleOrDefault(Expression<Func<Ubezpieczenie, bool>> expression) {

            var repo = GetRepo();
            var results=repo.Find(expression);
            Ubezpieczenie single=null;
            if(results.Count() > 0){
                single=results.ToList()[0];
                single.OnLoaded();
                single.SetIsLoaded(true);
                single.SetIsNew(false);
            }

            return single;
        }      
        
        public static Ubezpieczenie SingleOrDefault(Expression<Func<Ubezpieczenie, bool>> expression,string connectionString, string providerName) {
            var repo = GetRepo(connectionString,providerName);
            var results=repo.Find(expression);
            Ubezpieczenie single=null;
            if(results.Count() > 0){
                single=results.ToList()[0];
            }

            return single;


        }
        
        
        public static bool Exists(Expression<Func<Ubezpieczenie, bool>> expression,string connectionString, string providerName) {
           
            return All(connectionString,providerName).Any(expression);
        }        
        public static bool Exists(Expression<Func<Ubezpieczenie, bool>> expression) {
           
            return All().Any(expression);
        }        

        public static IList<Ubezpieczenie> Find(Expression<Func<Ubezpieczenie, bool>> expression) {
            
            var repo = GetRepo();
            return repo.Find(expression).ToList();
        }
        
        public static IList<Ubezpieczenie> Find(Expression<Func<Ubezpieczenie, bool>> expression,string connectionString, string providerName) {

            var repo = GetRepo(connectionString,providerName);
            return repo.Find(expression).ToList();

        }
        public static IQueryable<Ubezpieczenie> All(string connectionString, string providerName) {
            return GetRepo(connectionString,providerName).GetAll();
        }
        public static IQueryable<Ubezpieczenie> All() {
            return GetRepo().GetAll();
        }
        
        public static PagedList<Ubezpieczenie> GetPaged(string sortBy, int pageIndex, int pageSize,string connectionString, string providerName) {
            return GetRepo(connectionString,providerName).GetPaged(sortBy, pageIndex, pageSize);
        }
      
        public static PagedList<Ubezpieczenie> GetPaged(string sortBy, int pageIndex, int pageSize) {
            return GetRepo().GetPaged(sortBy, pageIndex, pageSize);
        }

        public static PagedList<Ubezpieczenie> GetPaged(int pageIndex, int pageSize,string connectionString, string providerName) {
            return GetRepo(connectionString,providerName).GetPaged(pageIndex, pageSize);
            
        }


        public static PagedList<Ubezpieczenie> GetPaged(int pageIndex, int pageSize) {
            return GetRepo().GetPaged(pageIndex, pageSize);
            
        }

        public string KeyName()
        {
            return "id";
        }

        public object KeyValue()
        {
            return this.id;
        }
        
        public void SetKeyValue(object value) {
            if (value != null && value!=DBNull.Value) {
                var settable = value.ChangeTypeTo<int>();
                this.GetType().GetProperty(this.KeyName()).SetValue(this, settable, null);
            }
        }
        
        public override string ToString(){
                            return this.kodTytuluUbezpieczenia.ToString();
                    }

        public override bool Equals(object obj){
            if(obj.GetType()==typeof(Ubezpieczenie)){
                Ubezpieczenie compare=(Ubezpieczenie)obj;
                return compare.KeyValue()==this.KeyValue();
            }else{
                return base.Equals(obj);
            }
        }

        
        public override int GetHashCode() {
            return this.id;
        }
        
        public string DescriptorValue()
        {
                            return this.kodTytuluUbezpieczenia.ToString();
                    }

        public string DescriptorColumn() {
            return "kodTytuluUbezpieczenia";
        }
        public static string GetKeyColumn()
        {
            return "id";
        }        
        public static string GetDescriptorColumn()
        {
            return "kodTytuluUbezpieczenia";
        }
        
        #region ' Foreign Keys '
        #endregion
        

        int _id;
        public int id
        {
            get { return _id; }
            set
            {
                if(_id!=value){
                    _id=value;
                    var col=tbl.Columns.SingleOrDefault(x=>x.Name=="id");
                    if(col!=null){
                        if(!_dirtyColumns.Any(x=>x.Name==col.Name) && _isLoaded){
                            _dirtyColumns.Add(col);
                        }
                    }
                    OnChanged();
                }
            }
        }

        int? _id_prac;
        public int? id_prac
        {
            get { return _id_prac; }
            set
            {
                if(_id_prac!=value){
                    _id_prac=value;
                    var col=tbl.Columns.SingleOrDefault(x=>x.Name=="id_prac");
                    if(col!=null){
                        if(!_dirtyColumns.Any(x=>x.Name==col.Name) && _isLoaded){
                            _dirtyColumns.Add(col);
                        }
                    }
                    OnChanged();
                }
            }
        }

        string _kodTytuluUbezpieczenia;
        public string kodTytuluUbezpieczenia
        {
            get { return _kodTytuluUbezpieczenia; }
            set
            {
                if(_kodTytuluUbezpieczenia!=value){
                    _kodTytuluUbezpieczenia=value;
                    var col=tbl.Columns.SingleOrDefault(x=>x.Name=="kodTytuluUbezpieczenia");
                    if(col!=null){
                        if(!_dirtyColumns.Any(x=>x.Name==col.Name) && _isLoaded){
                            _dirtyColumns.Add(col);
                        }
                    }
                    OnChanged();
                }
            }
        }

        string _niepelnosprawnoscOd;
        public string niepelnosprawnoscOd
        {
            get { return _niepelnosprawnoscOd; }
            set
            {
                if(_niepelnosprawnoscOd!=value){
                    _niepelnosprawnoscOd=value;
                    var col=tbl.Columns.SingleOrDefault(x=>x.Name=="niepelnosprawnoscOd");
                    if(col!=null){
                        if(!_dirtyColumns.Any(x=>x.Name==col.Name) && _isLoaded){
                            _dirtyColumns.Add(col);
                        }
                    }
                    OnChanged();
                }
            }
        }

        string _niepelnosprawnoscDo;
        public string niepelnosprawnoscDo
        {
            get { return _niepelnosprawnoscDo; }
            set
            {
                if(_niepelnosprawnoscDo!=value){
                    _niepelnosprawnoscDo=value;
                    var col=tbl.Columns.SingleOrDefault(x=>x.Name=="niepelnosprawnoscDo");
                    if(col!=null){
                        if(!_dirtyColumns.Any(x=>x.Name==col.Name) && _isLoaded){
                            _dirtyColumns.Add(col);
                        }
                    }
                    OnChanged();
                }
            }
        }

        string _kodOddzialuNFZ;
        public string kodOddzialuNFZ
        {
            get { return _kodOddzialuNFZ; }
            set
            {
                if(_kodOddzialuNFZ!=value){
                    _kodOddzialuNFZ=value;
                    var col=tbl.Columns.SingleOrDefault(x=>x.Name=="kodOddzialuNFZ");
                    if(col!=null){
                        if(!_dirtyColumns.Any(x=>x.Name==col.Name) && _isLoaded){
                            _dirtyColumns.Add(col);
                        }
                    }
                    OnChanged();
                }
            }
        }

        string _dataPrzystapieniaDoNFZ;
        public string dataPrzystapieniaDoNFZ
        {
            get { return _dataPrzystapieniaDoNFZ; }
            set
            {
                if(_dataPrzystapieniaDoNFZ!=value){
                    _dataPrzystapieniaDoNFZ=value;
                    var col=tbl.Columns.SingleOrDefault(x=>x.Name=="dataPrzystapieniaDoNFZ");
                    if(col!=null){
                        if(!_dirtyColumns.Any(x=>x.Name==col.Name) && _isLoaded){
                            _dirtyColumns.Add(col);
                        }
                    }
                    OnChanged();
                }
            }
        }

        bool? _podlegaUbEmerytalnemu;
        public bool? podlegaUbEmerytalnemu
        {
            get { return _podlegaUbEmerytalnemu; }
            set
            {
                if(_podlegaUbEmerytalnemu!=value){
                    _podlegaUbEmerytalnemu=value;
                    var col=tbl.Columns.SingleOrDefault(x=>x.Name=="podlegaUbEmerytalnemu");
                    if(col!=null){
                        if(!_dirtyColumns.Any(x=>x.Name==col.Name) && _isLoaded){
                            _dirtyColumns.Add(col);
                        }
                    }
                    OnChanged();
                }
            }
        }

        bool? _podlegaUbRentowemu;
        public bool? podlegaUbRentowemu
        {
            get { return _podlegaUbRentowemu; }
            set
            {
                if(_podlegaUbRentowemu!=value){
                    _podlegaUbRentowemu=value;
                    var col=tbl.Columns.SingleOrDefault(x=>x.Name=="podlegaUbRentowemu");
                    if(col!=null){
                        if(!_dirtyColumns.Any(x=>x.Name==col.Name) && _isLoaded){
                            _dirtyColumns.Add(col);
                        }
                    }
                    OnChanged();
                }
            }
        }

        bool? _podlegaUbChorobowemu;
        public bool? podlegaUbChorobowemu
        {
            get { return _podlegaUbChorobowemu; }
            set
            {
                if(_podlegaUbChorobowemu!=value){
                    _podlegaUbChorobowemu=value;
                    var col=tbl.Columns.SingleOrDefault(x=>x.Name=="podlegaUbChorobowemu");
                    if(col!=null){
                        if(!_dirtyColumns.Any(x=>x.Name==col.Name) && _isLoaded){
                            _dirtyColumns.Add(col);
                        }
                    }
                    OnChanged();
                }
            }
        }

        bool? _podlegaUbWypadkowemu;
        public bool? podlegaUbWypadkowemu
        {
            get { return _podlegaUbWypadkowemu; }
            set
            {
                if(_podlegaUbWypadkowemu!=value){
                    _podlegaUbWypadkowemu=value;
                    var col=tbl.Columns.SingleOrDefault(x=>x.Name=="podlegaUbWypadkowemu");
                    if(col!=null){
                        if(!_dirtyColumns.Any(x=>x.Name==col.Name) && _isLoaded){
                            _dirtyColumns.Add(col);
                        }
                    }
                    OnChanged();
                }
            }
        }

        bool? _podlegaUbZdrowotnemu;
        public bool? podlegaUbZdrowotnemu
        {
            get { return _podlegaUbZdrowotnemu; }
            set
            {
                if(_podlegaUbZdrowotnemu!=value){
                    _podlegaUbZdrowotnemu=value;
                    var col=tbl.Columns.SingleOrDefault(x=>x.Name=="podlegaUbZdrowotnemu");
                    if(col!=null){
                        if(!_dirtyColumns.Any(x=>x.Name==col.Name) && _isLoaded){
                            _dirtyColumns.Add(col);
                        }
                    }
                    OnChanged();
                }
            }
        }



        public DbCommand GetUpdateCommand() {
            if(TestMode)
                return _db.DataProvider.CreateCommand();
            else
                return this.ToUpdateQuery(_db.Provider).GetCommand().ToDbCommand();
            
        }
        public DbCommand GetInsertCommand() {
 
            if(TestMode)
                return _db.DataProvider.CreateCommand();
            else
                return this.ToInsertQuery(_db.Provider).GetCommand().ToDbCommand();
        }
        
        public DbCommand GetDeleteCommand() {
            if(TestMode)
                return _db.DataProvider.CreateCommand();
            else
                return this.ToDeleteQuery(_db.Provider).GetCommand().ToDbCommand();
        }
       
        
        public void Update(){
            Update(_db.DataProvider);
        }
        
        public void Update(IDataProvider provider){
        
            
            if(this._dirtyColumns.Count>0){
                _repo.Update(this,provider);
                _dirtyColumns.Clear();    
            }
            OnSaved();
       }
 
        public void Add(){
            Add(_db.DataProvider);
        }
        
        
       
        public void Add(IDataProvider provider){

            
            var key=KeyValue();
            if(key==null){
                var newKey=_repo.Add(this,provider);
                this.SetKeyValue(newKey);
            }else{
                _repo.Add(this,provider);
            }
            SetIsNew(false);
            OnSaved();
        }
        
                
        
        public void Save() {
            Save(_db.DataProvider);
        }      
        public void Save(IDataProvider provider) {
            
           
            if (_isNew) {
                Add(provider);
                
            } else {
                Update(provider);
            }
            
        }

        

        public void Delete(IDataProvider provider) {
                   
                 
            _repo.Delete(KeyValue());
            
                    }


        public void Delete() {
            Delete(_db.DataProvider);
        }


        public static void Delete(Expression<Func<Ubezpieczenie, bool>> expression) {
            var repo = GetRepo();
            
       
            
            repo.DeleteMany(expression);
            
        }

        

        public void Load(IDataReader rdr) {
            Load(rdr, true);
        }
        public void Load(IDataReader rdr, bool closeReader) {
            if (rdr.Read()) {

                try {
                    rdr.Load(this);
                    SetIsNew(false);
                    SetIsLoaded(true);
                } catch {
                    SetIsLoaded(false);
                    throw;
                }
            }else{
                SetIsLoaded(false);
            }

            if (closeReader)
                rdr.Dispose();
        }
        

    } 
    
    
    /// <summary>
    /// A class which represents the Urlopy table in the evolution Database.
    /// </summary>
    public partial class Urlopy: IActiveRecord
    {
    
        #region Built-in testing
        static TestRepository<Urlopy> _testRepo;
        

        
        static void SetTestRepo(){
            _testRepo = _testRepo ?? new TestRepository<Urlopy>(new Amortyzacje.Model.evolutionDB());
        }
        public static void ResetTestRepo(){
            _testRepo = null;
            SetTestRepo();
        }
        public static void Setup(List<Urlopy> testlist){
            SetTestRepo();
            foreach (var item in testlist)
            {
                _testRepo._items.Add(item);
            }
        }
        public static void Setup(Urlopy item) {
            SetTestRepo();
            _testRepo._items.Add(item);
        }
        public static void Setup(int testItems) {
            SetTestRepo();
            for(int i=0;i<testItems;i++){
                Urlopy item=new Urlopy();
                _testRepo._items.Add(item);
            }
        }
        
        public bool TestMode = false;


        #endregion

        IRepository<Urlopy> _repo;
        ITable tbl;
        bool _isNew;
        public bool IsNew(){
            return _isNew;
        }
        
        public void SetIsLoaded(bool isLoaded){
            _isLoaded=isLoaded;
            if(isLoaded)
                OnLoaded();
        }
        
        public void SetIsNew(bool isNew){
            _isNew=isNew;
        }
        bool _isLoaded;
        public bool IsLoaded(){
            return _isLoaded;
        }
                
        List<IColumn> _dirtyColumns;
        public bool IsDirty(){
            return _dirtyColumns.Count>0;
        }
        
        public List<IColumn> GetDirtyColumns (){
            return _dirtyColumns;
        }

        Amortyzacje.Model.evolutionDB _db;
        public Urlopy(string connectionString, string providerName) {

            _db=new Amortyzacje.Model.evolutionDB(connectionString, providerName);
            Init();            
         }
        void Init(){
            TestMode=this._db.DataProvider.ConnectionString.Equals("test", StringComparison.InvariantCultureIgnoreCase);
            _dirtyColumns=new List<IColumn>();
            if(TestMode){
                Urlopy.SetTestRepo();
                _repo=_testRepo;
            }else{
                _repo = new SubSonicRepository<Urlopy>(_db);
            }
            tbl=_repo.GetTable();
            SetIsNew(true);
            OnCreated();       

        }
        
        public Urlopy(){
             _db=new Amortyzacje.Model.evolutionDB();
            Init();            
        }
        
       
        partial void OnCreated();
            
        partial void OnLoaded();
        
        partial void OnSaved();
        
        partial void OnChanged();
        
        public IList<IColumn> Columns{
            get{
                return tbl.Columns;
            }
        }

        public Urlopy(Expression<Func<Urlopy, bool>> expression):this() {

            SetIsLoaded(_repo.Load(this,expression));
        }
        
       
        
        internal static IRepository<Urlopy> GetRepo(string connectionString, string providerName){
            Amortyzacje.Model.evolutionDB db;
            if(String.IsNullOrEmpty(connectionString)){
                db=new Amortyzacje.Model.evolutionDB();
            }else{
                db=new Amortyzacje.Model.evolutionDB(connectionString, providerName);
            }
            IRepository<Urlopy> _repo;
            
            if(db.TestMode){
                Urlopy.SetTestRepo();
                _repo=_testRepo;
            }else{
                _repo = new SubSonicRepository<Urlopy>(db);
            }
            return _repo;        
        }       
        
        internal static IRepository<Urlopy> GetRepo(){
            return GetRepo("","");
        }
        
        public static Urlopy SingleOrDefault(Expression<Func<Urlopy, bool>> expression) {

            var repo = GetRepo();
            var results=repo.Find(expression);
            Urlopy single=null;
            if(results.Count() > 0){
                single=results.ToList()[0];
                single.OnLoaded();
                single.SetIsLoaded(true);
                single.SetIsNew(false);
            }

            return single;
        }      
        
        public static Urlopy SingleOrDefault(Expression<Func<Urlopy, bool>> expression,string connectionString, string providerName) {
            var repo = GetRepo(connectionString,providerName);
            var results=repo.Find(expression);
            Urlopy single=null;
            if(results.Count() > 0){
                single=results.ToList()[0];
            }

            return single;


        }
        
        
        public static bool Exists(Expression<Func<Urlopy, bool>> expression,string connectionString, string providerName) {
           
            return All(connectionString,providerName).Any(expression);
        }        
        public static bool Exists(Expression<Func<Urlopy, bool>> expression) {
           
            return All().Any(expression);
        }        

        public static IList<Urlopy> Find(Expression<Func<Urlopy, bool>> expression) {
            
            var repo = GetRepo();
            return repo.Find(expression).ToList();
        }
        
        public static IList<Urlopy> Find(Expression<Func<Urlopy, bool>> expression,string connectionString, string providerName) {

            var repo = GetRepo(connectionString,providerName);
            return repo.Find(expression).ToList();

        }
        public static IQueryable<Urlopy> All(string connectionString, string providerName) {
            return GetRepo(connectionString,providerName).GetAll();
        }
        public static IQueryable<Urlopy> All() {
            return GetRepo().GetAll();
        }
        
        public static PagedList<Urlopy> GetPaged(string sortBy, int pageIndex, int pageSize,string connectionString, string providerName) {
            return GetRepo(connectionString,providerName).GetPaged(sortBy, pageIndex, pageSize);
        }
      
        public static PagedList<Urlopy> GetPaged(string sortBy, int pageIndex, int pageSize) {
            return GetRepo().GetPaged(sortBy, pageIndex, pageSize);
        }

        public static PagedList<Urlopy> GetPaged(int pageIndex, int pageSize,string connectionString, string providerName) {
            return GetRepo(connectionString,providerName).GetPaged(pageIndex, pageSize);
            
        }


        public static PagedList<Urlopy> GetPaged(int pageIndex, int pageSize) {
            return GetRepo().GetPaged(pageIndex, pageSize);
            
        }

        public string KeyName()
        {
            return "id";
        }

        public object KeyValue()
        {
            return this.id;
        }
        
        public void SetKeyValue(object value) {
            if (value != null && value!=DBNull.Value) {
                var settable = value.ChangeTypeTo<int>();
                this.GetType().GetProperty(this.KeyName()).SetValue(this, settable, null);
            }
        }
        
        public override string ToString(){
                            return this.typUrlopu.ToString();
                    }

        public override bool Equals(object obj){
            if(obj.GetType()==typeof(Urlopy)){
                Urlopy compare=(Urlopy)obj;
                return compare.KeyValue()==this.KeyValue();
            }else{
                return base.Equals(obj);
            }
        }

        
        public override int GetHashCode() {
            return this.id;
        }
        
        public string DescriptorValue()
        {
                            return this.typUrlopu.ToString();
                    }

        public string DescriptorColumn() {
            return "typUrlopu";
        }
        public static string GetKeyColumn()
        {
            return "id";
        }        
        public static string GetDescriptorColumn()
        {
            return "typUrlopu";
        }
        
        #region ' Foreign Keys '
        #endregion
        

        int _id;
        public int id
        {
            get { return _id; }
            set
            {
                if(_id!=value){
                    _id=value;
                    var col=tbl.Columns.SingleOrDefault(x=>x.Name=="id");
                    if(col!=null){
                        if(!_dirtyColumns.Any(x=>x.Name==col.Name) && _isLoaded){
                            _dirtyColumns.Add(col);
                        }
                    }
                    OnChanged();
                }
            }
        }

        int? _id_prac;
        public int? id_prac
        {
            get { return _id_prac; }
            set
            {
                if(_id_prac!=value){
                    _id_prac=value;
                    var col=tbl.Columns.SingleOrDefault(x=>x.Name=="id_prac");
                    if(col!=null){
                        if(!_dirtyColumns.Any(x=>x.Name==col.Name) && _isLoaded){
                            _dirtyColumns.Add(col);
                        }
                    }
                    OnChanged();
                }
            }
        }

        string _typUrlopu;
        public string typUrlopu
        {
            get { return _typUrlopu; }
            set
            {
                if(_typUrlopu!=value){
                    _typUrlopu=value;
                    var col=tbl.Columns.SingleOrDefault(x=>x.Name=="typUrlopu");
                    if(col!=null){
                        if(!_dirtyColumns.Any(x=>x.Name==col.Name) && _isLoaded){
                            _dirtyColumns.Add(col);
                        }
                    }
                    OnChanged();
                }
            }
        }

        string _urlopOd;
        public string urlopOd
        {
            get { return _urlopOd; }
            set
            {
                if(_urlopOd!=value){
                    _urlopOd=value;
                    var col=tbl.Columns.SingleOrDefault(x=>x.Name=="urlopOd");
                    if(col!=null){
                        if(!_dirtyColumns.Any(x=>x.Name==col.Name) && _isLoaded){
                            _dirtyColumns.Add(col);
                        }
                    }
                    OnChanged();
                }
            }
        }

        string _urlopDo;
        public string urlopDo
        {
            get { return _urlopDo; }
            set
            {
                if(_urlopDo!=value){
                    _urlopDo=value;
                    var col=tbl.Columns.SingleOrDefault(x=>x.Name=="urlopDo");
                    if(col!=null){
                        if(!_dirtyColumns.Any(x=>x.Name==col.Name) && _isLoaded){
                            _dirtyColumns.Add(col);
                        }
                    }
                    OnChanged();
                }
            }
        }

        int? _liczbaWykorzystanychDni;
        public int? liczbaWykorzystanychDni
        {
            get { return _liczbaWykorzystanychDni; }
            set
            {
                if(_liczbaWykorzystanychDni!=value){
                    _liczbaWykorzystanychDni=value;
                    var col=tbl.Columns.SingleOrDefault(x=>x.Name=="liczbaWykorzystanychDni");
                    if(col!=null){
                        if(!_dirtyColumns.Any(x=>x.Name==col.Name) && _isLoaded){
                            _dirtyColumns.Add(col);
                        }
                    }
                    OnChanged();
                }
            }
        }

        int? _liczbaPozostalychDni;
        public int? liczbaPozostalychDni
        {
            get { return _liczbaPozostalychDni; }
            set
            {
                if(_liczbaPozostalychDni!=value){
                    _liczbaPozostalychDni=value;
                    var col=tbl.Columns.SingleOrDefault(x=>x.Name=="liczbaPozostalychDni");
                    if(col!=null){
                        if(!_dirtyColumns.Any(x=>x.Name==col.Name) && _isLoaded){
                            _dirtyColumns.Add(col);
                        }
                    }
                    OnChanged();
                }
            }
        }



        public DbCommand GetUpdateCommand() {
            if(TestMode)
                return _db.DataProvider.CreateCommand();
            else
                return this.ToUpdateQuery(_db.Provider).GetCommand().ToDbCommand();
            
        }
        public DbCommand GetInsertCommand() {
 
            if(TestMode)
                return _db.DataProvider.CreateCommand();
            else
                return this.ToInsertQuery(_db.Provider).GetCommand().ToDbCommand();
        }
        
        public DbCommand GetDeleteCommand() {
            if(TestMode)
                return _db.DataProvider.CreateCommand();
            else
                return this.ToDeleteQuery(_db.Provider).GetCommand().ToDbCommand();
        }
       
        
        public void Update(){
            Update(_db.DataProvider);
        }
        
        public void Update(IDataProvider provider){
        
            
            if(this._dirtyColumns.Count>0){
                _repo.Update(this,provider);
                _dirtyColumns.Clear();    
            }
            OnSaved();
       }
 
        public void Add(){
            Add(_db.DataProvider);
        }
        
        
       
        public void Add(IDataProvider provider){

            
            var key=KeyValue();
            if(key==null){
                var newKey=_repo.Add(this,provider);
                this.SetKeyValue(newKey);
            }else{
                _repo.Add(this,provider);
            }
            SetIsNew(false);
            OnSaved();
        }
        
                
        
        public void Save() {
            Save(_db.DataProvider);
        }      
        public void Save(IDataProvider provider) {
            
           
            if (_isNew) {
                Add(provider);
                
            } else {
                Update(provider);
            }
            
        }

        

        public void Delete(IDataProvider provider) {
                   
                 
            _repo.Delete(KeyValue());
            
                    }


        public void Delete() {
            Delete(_db.DataProvider);
        }


        public static void Delete(Expression<Func<Urlopy, bool>> expression) {
            var repo = GetRepo();
            
       
            
            repo.DeleteMany(expression);
            
        }

        

        public void Load(IDataReader rdr) {
            Load(rdr, true);
        }
        public void Load(IDataReader rdr, bool closeReader) {
            if (rdr.Read()) {

                try {
                    rdr.Load(this);
                    SetIsNew(false);
                    SetIsLoaded(true);
                } catch {
                    SetIsLoaded(false);
                    throw;
                }
            }else{
                SetIsLoaded(false);
            }

            if (closeReader)
                rdr.Dispose();
        }
        

    } 
    
    
    /// <summary>
    /// A class which represents the Wyplata table in the evolution Database.
    /// </summary>
    public partial class Wyplatum: IActiveRecord
    {
    
        #region Built-in testing
        static TestRepository<Wyplatum> _testRepo;
        

        
        static void SetTestRepo(){
            _testRepo = _testRepo ?? new TestRepository<Wyplatum>(new Amortyzacje.Model.evolutionDB());
        }
        public static void ResetTestRepo(){
            _testRepo = null;
            SetTestRepo();
        }
        public static void Setup(List<Wyplatum> testlist){
            SetTestRepo();
            foreach (var item in testlist)
            {
                _testRepo._items.Add(item);
            }
        }
        public static void Setup(Wyplatum item) {
            SetTestRepo();
            _testRepo._items.Add(item);
        }
        public static void Setup(int testItems) {
            SetTestRepo();
            for(int i=0;i<testItems;i++){
                Wyplatum item=new Wyplatum();
                _testRepo._items.Add(item);
            }
        }
        
        public bool TestMode = false;


        #endregion

        IRepository<Wyplatum> _repo;
        ITable tbl;
        bool _isNew;
        public bool IsNew(){
            return _isNew;
        }
        
        public void SetIsLoaded(bool isLoaded){
            _isLoaded=isLoaded;
            if(isLoaded)
                OnLoaded();
        }
        
        public void SetIsNew(bool isNew){
            _isNew=isNew;
        }
        bool _isLoaded;
        public bool IsLoaded(){
            return _isLoaded;
        }
                
        List<IColumn> _dirtyColumns;
        public bool IsDirty(){
            return _dirtyColumns.Count>0;
        }
        
        public List<IColumn> GetDirtyColumns (){
            return _dirtyColumns;
        }

        Amortyzacje.Model.evolutionDB _db;
        public Wyplatum(string connectionString, string providerName) {

            _db=new Amortyzacje.Model.evolutionDB(connectionString, providerName);
            Init();            
         }
        void Init(){
            TestMode=this._db.DataProvider.ConnectionString.Equals("test", StringComparison.InvariantCultureIgnoreCase);
            _dirtyColumns=new List<IColumn>();
            if(TestMode){
                Wyplatum.SetTestRepo();
                _repo=_testRepo;
            }else{
                _repo = new SubSonicRepository<Wyplatum>(_db);
            }
            tbl=_repo.GetTable();
            SetIsNew(true);
            OnCreated();       

        }
        
        public Wyplatum(){
             _db=new Amortyzacje.Model.evolutionDB();
            Init();            
        }
        
       
        partial void OnCreated();
            
        partial void OnLoaded();
        
        partial void OnSaved();
        
        partial void OnChanged();
        
        public IList<IColumn> Columns{
            get{
                return tbl.Columns;
            }
        }

        public Wyplatum(Expression<Func<Wyplatum, bool>> expression):this() {

            SetIsLoaded(_repo.Load(this,expression));
        }
        
       
        
        internal static IRepository<Wyplatum> GetRepo(string connectionString, string providerName){
            Amortyzacje.Model.evolutionDB db;
            if(String.IsNullOrEmpty(connectionString)){
                db=new Amortyzacje.Model.evolutionDB();
            }else{
                db=new Amortyzacje.Model.evolutionDB(connectionString, providerName);
            }
            IRepository<Wyplatum> _repo;
            
            if(db.TestMode){
                Wyplatum.SetTestRepo();
                _repo=_testRepo;
            }else{
                _repo = new SubSonicRepository<Wyplatum>(db);
            }
            return _repo;        
        }       
        
        internal static IRepository<Wyplatum> GetRepo(){
            return GetRepo("","");
        }
        
        public static Wyplatum SingleOrDefault(Expression<Func<Wyplatum, bool>> expression) {

            var repo = GetRepo();
            var results=repo.Find(expression);
            Wyplatum single=null;
            if(results.Count() > 0){
                single=results.ToList()[0];
                single.OnLoaded();
                single.SetIsLoaded(true);
                single.SetIsNew(false);
            }

            return single;
        }      
        
        public static Wyplatum SingleOrDefault(Expression<Func<Wyplatum, bool>> expression,string connectionString, string providerName) {
            var repo = GetRepo(connectionString,providerName);
            var results=repo.Find(expression);
            Wyplatum single=null;
            if(results.Count() > 0){
                single=results.ToList()[0];
            }

            return single;


        }
        
        
        public static bool Exists(Expression<Func<Wyplatum, bool>> expression,string connectionString, string providerName) {
           
            return All(connectionString,providerName).Any(expression);
        }        
        public static bool Exists(Expression<Func<Wyplatum, bool>> expression) {
           
            return All().Any(expression);
        }        

        public static IList<Wyplatum> Find(Expression<Func<Wyplatum, bool>> expression) {
            
            var repo = GetRepo();
            return repo.Find(expression).ToList();
        }
        
        public static IList<Wyplatum> Find(Expression<Func<Wyplatum, bool>> expression,string connectionString, string providerName) {

            var repo = GetRepo(connectionString,providerName);
            return repo.Find(expression).ToList();

        }
        public static IQueryable<Wyplatum> All(string connectionString, string providerName) {
            return GetRepo(connectionString,providerName).GetAll();
        }
        public static IQueryable<Wyplatum> All() {
            return GetRepo().GetAll();
        }
        
        public static PagedList<Wyplatum> GetPaged(string sortBy, int pageIndex, int pageSize,string connectionString, string providerName) {
            return GetRepo(connectionString,providerName).GetPaged(sortBy, pageIndex, pageSize);
        }
      
        public static PagedList<Wyplatum> GetPaged(string sortBy, int pageIndex, int pageSize) {
            return GetRepo().GetPaged(sortBy, pageIndex, pageSize);
        }

        public static PagedList<Wyplatum> GetPaged(int pageIndex, int pageSize,string connectionString, string providerName) {
            return GetRepo(connectionString,providerName).GetPaged(pageIndex, pageSize);
            
        }


        public static PagedList<Wyplatum> GetPaged(int pageIndex, int pageSize) {
            return GetRepo().GetPaged(pageIndex, pageSize);
            
        }

        public string KeyName()
        {
            return "idWyplaty";
        }

        public object KeyValue()
        {
            return this.idWyplaty;
        }
        
        public void SetKeyValue(object value) {
            if (value != null && value!=DBNull.Value) {
                var settable = value.ChangeTypeTo<int>();
                this.GetType().GetProperty(this.KeyName()).SetValue(this, settable, null);
            }
        }
        
        public override string ToString(){
                            return this.kwotaZlecenia.ToString();
                    }

        public override bool Equals(object obj){
            if(obj.GetType()==typeof(Wyplatum)){
                Wyplatum compare=(Wyplatum)obj;
                return compare.KeyValue()==this.KeyValue();
            }else{
                return base.Equals(obj);
            }
        }

        
        public override int GetHashCode() {
            return this.idWyplaty;
        }
        
        public string DescriptorValue()
        {
                            return this.kwotaZlecenia.ToString();
                    }

        public string DescriptorColumn() {
            return "kwotaZlecenia";
        }
        public static string GetKeyColumn()
        {
            return "idWyplaty";
        }        
        public static string GetDescriptorColumn()
        {
            return "kwotaZlecenia";
        }
        
        #region ' Foreign Keys '
        #endregion
        

        int _idWyplaty;
        public int idWyplaty
        {
            get { return _idWyplaty; }
            set
            {
                if(_idWyplaty!=value){
                    _idWyplaty=value;
                    var col=tbl.Columns.SingleOrDefault(x=>x.Name=="idWyplaty");
                    if(col!=null){
                        if(!_dirtyColumns.Any(x=>x.Name==col.Name) && _isLoaded){
                            _dirtyColumns.Add(col);
                        }
                    }
                    OnChanged();
                }
            }
        }

        int? _id_prac;
        public int? id_prac
        {
            get { return _id_prac; }
            set
            {
                if(_id_prac!=value){
                    _id_prac=value;
                    var col=tbl.Columns.SingleOrDefault(x=>x.Name=="id_prac");
                    if(col!=null){
                        if(!_dirtyColumns.Any(x=>x.Name==col.Name) && _isLoaded){
                            _dirtyColumns.Add(col);
                        }
                    }
                    OnChanged();
                }
            }
        }

        string _kwotaZlecenia;
        public string kwotaZlecenia
        {
            get { return _kwotaZlecenia; }
            set
            {
                if(_kwotaZlecenia!=value){
                    _kwotaZlecenia=value;
                    var col=tbl.Columns.SingleOrDefault(x=>x.Name=="kwotaZlecenia");
                    if(col!=null){
                        if(!_dirtyColumns.Any(x=>x.Name==col.Name) && _isLoaded){
                            _dirtyColumns.Add(col);
                        }
                    }
                    OnChanged();
                }
            }
        }

        string _rok;
        public string rok
        {
            get { return _rok; }
            set
            {
                if(_rok!=value){
                    _rok=value;
                    var col=tbl.Columns.SingleOrDefault(x=>x.Name=="rok");
                    if(col!=null){
                        if(!_dirtyColumns.Any(x=>x.Name==col.Name) && _isLoaded){
                            _dirtyColumns.Add(col);
                        }
                    }
                    OnChanged();
                }
            }
        }

        string _miesiac;
        public string miesiac
        {
            get { return _miesiac; }
            set
            {
                if(_miesiac!=value){
                    _miesiac=value;
                    var col=tbl.Columns.SingleOrDefault(x=>x.Name=="miesiac");
                    if(col!=null){
                        if(!_dirtyColumns.Any(x=>x.Name==col.Name) && _isLoaded){
                            _dirtyColumns.Add(col);
                        }
                    }
                    OnChanged();
                }
            }
        }

        bool? _stanWyplaconoLubNie;
        public bool? stanWyplaconoLubNie
        {
            get { return _stanWyplaconoLubNie; }
            set
            {
                if(_stanWyplaconoLubNie!=value){
                    _stanWyplaconoLubNie=value;
                    var col=tbl.Columns.SingleOrDefault(x=>x.Name=="stanWyplaconoLubNie");
                    if(col!=null){
                        if(!_dirtyColumns.Any(x=>x.Name==col.Name) && _isLoaded){
                            _dirtyColumns.Add(col);
                        }
                    }
                    OnChanged();
                }
            }
        }

        string _dataWykonaniaZleceniaZaplaty;
        public string dataWykonaniaZleceniaZaplaty
        {
            get { return _dataWykonaniaZleceniaZaplaty; }
            set
            {
                if(_dataWykonaniaZleceniaZaplaty!=value){
                    _dataWykonaniaZleceniaZaplaty=value;
                    var col=tbl.Columns.SingleOrDefault(x=>x.Name=="dataWykonaniaZleceniaZaplaty");
                    if(col!=null){
                        if(!_dirtyColumns.Any(x=>x.Name==col.Name) && _isLoaded){
                            _dirtyColumns.Add(col);
                        }
                    }
                    OnChanged();
                }
            }
        }

        string _doPrzelewu;
        public string doPrzelewu
        {
            get { return _doPrzelewu; }
            set
            {
                if(_doPrzelewu!=value){
                    _doPrzelewu=value;
                    var col=tbl.Columns.SingleOrDefault(x=>x.Name=="doPrzelewu");
                    if(col!=null){
                        if(!_dirtyColumns.Any(x=>x.Name==col.Name) && _isLoaded){
                            _dirtyColumns.Add(col);
                        }
                    }
                    OnChanged();
                }
            }
        }



        public DbCommand GetUpdateCommand() {
            if(TestMode)
                return _db.DataProvider.CreateCommand();
            else
                return this.ToUpdateQuery(_db.Provider).GetCommand().ToDbCommand();
            
        }
        public DbCommand GetInsertCommand() {
 
            if(TestMode)
                return _db.DataProvider.CreateCommand();
            else
                return this.ToInsertQuery(_db.Provider).GetCommand().ToDbCommand();
        }
        
        public DbCommand GetDeleteCommand() {
            if(TestMode)
                return _db.DataProvider.CreateCommand();
            else
                return this.ToDeleteQuery(_db.Provider).GetCommand().ToDbCommand();
        }
       
        
        public void Update(){
            Update(_db.DataProvider);
        }
        
        public void Update(IDataProvider provider){
        
            
            if(this._dirtyColumns.Count>0){
                _repo.Update(this,provider);
                _dirtyColumns.Clear();    
            }
            OnSaved();
       }
 
        public void Add(){
            Add(_db.DataProvider);
        }
        
        
       
        public void Add(IDataProvider provider){

            
            var key=KeyValue();
            if(key==null){
                var newKey=_repo.Add(this,provider);
                this.SetKeyValue(newKey);
            }else{
                _repo.Add(this,provider);
            }
            SetIsNew(false);
            OnSaved();
        }
        
                
        
        public void Save() {
            Save(_db.DataProvider);
        }      
        public void Save(IDataProvider provider) {
            
           
            if (_isNew) {
                Add(provider);
                
            } else {
                Update(provider);
            }
            
        }

        

        public void Delete(IDataProvider provider) {
                   
                 
            _repo.Delete(KeyValue());
            
                    }


        public void Delete() {
            Delete(_db.DataProvider);
        }


        public static void Delete(Expression<Func<Wyplatum, bool>> expression) {
            var repo = GetRepo();
            
       
            
            repo.DeleteMany(expression);
            
        }

        

        public void Load(IDataReader rdr) {
            Load(rdr, true);
        }
        public void Load(IDataReader rdr, bool closeReader) {
            if (rdr.Read()) {

                try {
                    rdr.Load(this);
                    SetIsNew(false);
                    SetIsLoaded(true);
                } catch {
                    SetIsLoaded(false);
                    throw;
                }
            }else{
                SetIsLoaded(false);
            }

            if (closeReader)
                rdr.Dispose();
        }
        

    } 
    
    
    /// <summary>
    /// A class which represents the Zatrudnienie table in the evolution Database.
    /// </summary>
    public partial class Zatrudnienie: IActiveRecord
    {
    
        #region Built-in testing
        static TestRepository<Zatrudnienie> _testRepo;
        

        
        static void SetTestRepo(){
            _testRepo = _testRepo ?? new TestRepository<Zatrudnienie>(new Amortyzacje.Model.evolutionDB());
        }
        public static void ResetTestRepo(){
            _testRepo = null;
            SetTestRepo();
        }
        public static void Setup(List<Zatrudnienie> testlist){
            SetTestRepo();
            foreach (var item in testlist)
            {
                _testRepo._items.Add(item);
            }
        }
        public static void Setup(Zatrudnienie item) {
            SetTestRepo();
            _testRepo._items.Add(item);
        }
        public static void Setup(int testItems) {
            SetTestRepo();
            for(int i=0;i<testItems;i++){
                Zatrudnienie item=new Zatrudnienie();
                _testRepo._items.Add(item);
            }
        }
        
        public bool TestMode = false;


        #endregion

        IRepository<Zatrudnienie> _repo;
        ITable tbl;
        bool _isNew;
        public bool IsNew(){
            return _isNew;
        }
        
        public void SetIsLoaded(bool isLoaded){
            _isLoaded=isLoaded;
            if(isLoaded)
                OnLoaded();
        }
        
        public void SetIsNew(bool isNew){
            _isNew=isNew;
        }
        bool _isLoaded;
        public bool IsLoaded(){
            return _isLoaded;
        }
                
        List<IColumn> _dirtyColumns;
        public bool IsDirty(){
            return _dirtyColumns.Count>0;
        }
        
        public List<IColumn> GetDirtyColumns (){
            return _dirtyColumns;
        }

        Amortyzacje.Model.evolutionDB _db;
        public Zatrudnienie(string connectionString, string providerName) {

            _db=new Amortyzacje.Model.evolutionDB(connectionString, providerName);
            Init();            
         }
        void Init(){
            TestMode=this._db.DataProvider.ConnectionString.Equals("test", StringComparison.InvariantCultureIgnoreCase);
            _dirtyColumns=new List<IColumn>();
            if(TestMode){
                Zatrudnienie.SetTestRepo();
                _repo=_testRepo;
            }else{
                _repo = new SubSonicRepository<Zatrudnienie>(_db);
            }
            tbl=_repo.GetTable();
            SetIsNew(true);
            OnCreated();       

        }
        
        public Zatrudnienie(){
             _db=new Amortyzacje.Model.evolutionDB();
            Init();            
        }
        
       
        partial void OnCreated();
            
        partial void OnLoaded();
        
        partial void OnSaved();
        
        partial void OnChanged();
        
        public IList<IColumn> Columns{
            get{
                return tbl.Columns;
            }
        }

        public Zatrudnienie(Expression<Func<Zatrudnienie, bool>> expression):this() {

            SetIsLoaded(_repo.Load(this,expression));
        }
        
       
        
        internal static IRepository<Zatrudnienie> GetRepo(string connectionString, string providerName){
            Amortyzacje.Model.evolutionDB db;
            if(String.IsNullOrEmpty(connectionString)){
                db=new Amortyzacje.Model.evolutionDB();
            }else{
                db=new Amortyzacje.Model.evolutionDB(connectionString, providerName);
            }
            IRepository<Zatrudnienie> _repo;
            
            if(db.TestMode){
                Zatrudnienie.SetTestRepo();
                _repo=_testRepo;
            }else{
                _repo = new SubSonicRepository<Zatrudnienie>(db);
            }
            return _repo;        
        }       
        
        internal static IRepository<Zatrudnienie> GetRepo(){
            return GetRepo("","");
        }
        
        public static Zatrudnienie SingleOrDefault(Expression<Func<Zatrudnienie, bool>> expression) {

            var repo = GetRepo();
            var results=repo.Find(expression);
            Zatrudnienie single=null;
            if(results.Count() > 0){
                single=results.ToList()[0];
                single.OnLoaded();
                single.SetIsLoaded(true);
                single.SetIsNew(false);
            }

            return single;
        }      
        
        public static Zatrudnienie SingleOrDefault(Expression<Func<Zatrudnienie, bool>> expression,string connectionString, string providerName) {
            var repo = GetRepo(connectionString,providerName);
            var results=repo.Find(expression);
            Zatrudnienie single=null;
            if(results.Count() > 0){
                single=results.ToList()[0];
            }

            return single;


        }
        
        
        public static bool Exists(Expression<Func<Zatrudnienie, bool>> expression,string connectionString, string providerName) {
           
            return All(connectionString,providerName).Any(expression);
        }        
        public static bool Exists(Expression<Func<Zatrudnienie, bool>> expression) {
           
            return All().Any(expression);
        }        

        public static IList<Zatrudnienie> Find(Expression<Func<Zatrudnienie, bool>> expression) {
            
            var repo = GetRepo();
            return repo.Find(expression).ToList();
        }
        
        public static IList<Zatrudnienie> Find(Expression<Func<Zatrudnienie, bool>> expression,string connectionString, string providerName) {

            var repo = GetRepo(connectionString,providerName);
            return repo.Find(expression).ToList();

        }
        public static IQueryable<Zatrudnienie> All(string connectionString, string providerName) {
            return GetRepo(connectionString,providerName).GetAll();
        }
        public static IQueryable<Zatrudnienie> All() {
            return GetRepo().GetAll();
        }
        
        public static PagedList<Zatrudnienie> GetPaged(string sortBy, int pageIndex, int pageSize,string connectionString, string providerName) {
            return GetRepo(connectionString,providerName).GetPaged(sortBy, pageIndex, pageSize);
        }
      
        public static PagedList<Zatrudnienie> GetPaged(string sortBy, int pageIndex, int pageSize) {
            return GetRepo().GetPaged(sortBy, pageIndex, pageSize);
        }

        public static PagedList<Zatrudnienie> GetPaged(int pageIndex, int pageSize,string connectionString, string providerName) {
            return GetRepo(connectionString,providerName).GetPaged(pageIndex, pageSize);
            
        }


        public static PagedList<Zatrudnienie> GetPaged(int pageIndex, int pageSize) {
            return GetRepo().GetPaged(pageIndex, pageSize);
            
        }

        public string KeyName()
        {
            return "id";
        }

        public object KeyValue()
        {
            return this.id;
        }
        
        public void SetKeyValue(object value) {
            if (value != null && value!=DBNull.Value) {
                var settable = value.ChangeTypeTo<int>();
                this.GetType().GetProperty(this.KeyName()).SetValue(this, settable, null);
            }
        }
        
        public override string ToString(){
                            return this.etat1.ToString();
                    }

        public override bool Equals(object obj){
            if(obj.GetType()==typeof(Zatrudnienie)){
                Zatrudnienie compare=(Zatrudnienie)obj;
                return compare.KeyValue()==this.KeyValue();
            }else{
                return base.Equals(obj);
            }
        }

        
        public override int GetHashCode() {
            return this.id;
        }
        
        public string DescriptorValue()
        {
                            return this.etat1.ToString();
                    }

        public string DescriptorColumn() {
            return "etat1";
        }
        public static string GetKeyColumn()
        {
            return "id";
        }        
        public static string GetDescriptorColumn()
        {
            return "etat1";
        }
        
        #region ' Foreign Keys '
        #endregion
        

        int _id;
        public int id
        {
            get { return _id; }
            set
            {
                if(_id!=value){
                    _id=value;
                    var col=tbl.Columns.SingleOrDefault(x=>x.Name=="id");
                    if(col!=null){
                        if(!_dirtyColumns.Any(x=>x.Name==col.Name) && _isLoaded){
                            _dirtyColumns.Add(col);
                        }
                    }
                    OnChanged();
                }
            }
        }

        int? _id_prac;
        public int? id_prac
        {
            get { return _id_prac; }
            set
            {
                if(_id_prac!=value){
                    _id_prac=value;
                    var col=tbl.Columns.SingleOrDefault(x=>x.Name=="id_prac");
                    if(col!=null){
                        if(!_dirtyColumns.Any(x=>x.Name==col.Name) && _isLoaded){
                            _dirtyColumns.Add(col);
                        }
                    }
                    OnChanged();
                }
            }
        }

        string _etat1;
        public string etat1
        {
            get { return _etat1; }
            set
            {
                if(_etat1!=value){
                    _etat1=value;
                    var col=tbl.Columns.SingleOrDefault(x=>x.Name=="etat1");
                    if(col!=null){
                        if(!_dirtyColumns.Any(x=>x.Name==col.Name) && _isLoaded){
                            _dirtyColumns.Add(col);
                        }
                    }
                    OnChanged();
                }
            }
        }

        string _etat2;
        public string etat2
        {
            get { return _etat2; }
            set
            {
                if(_etat2!=value){
                    _etat2=value;
                    var col=tbl.Columns.SingleOrDefault(x=>x.Name=="etat2");
                    if(col!=null){
                        if(!_dirtyColumns.Any(x=>x.Name==col.Name) && _isLoaded){
                            _dirtyColumns.Add(col);
                        }
                    }
                    OnChanged();
                }
            }
        }

        string _dataZatrudnienia;
        public string dataZatrudnienia
        {
            get { return _dataZatrudnienia; }
            set
            {
                if(_dataZatrudnienia!=value){
                    _dataZatrudnienia=value;
                    var col=tbl.Columns.SingleOrDefault(x=>x.Name=="dataZatrudnienia");
                    if(col!=null){
                        if(!_dirtyColumns.Any(x=>x.Name==col.Name) && _isLoaded){
                            _dirtyColumns.Add(col);
                        }
                    }
                    OnChanged();
                }
            }
        }

        string _dzial;
        public string dzial
        {
            get { return _dzial; }
            set
            {
                if(_dzial!=value){
                    _dzial=value;
                    var col=tbl.Columns.SingleOrDefault(x=>x.Name=="dzial");
                    if(col!=null){
                        if(!_dirtyColumns.Any(x=>x.Name==col.Name) && _isLoaded){
                            _dirtyColumns.Add(col);
                        }
                    }
                    OnChanged();
                }
            }
        }

        string _stanowisko;
        public string stanowisko
        {
            get { return _stanowisko; }
            set
            {
                if(_stanowisko!=value){
                    _stanowisko=value;
                    var col=tbl.Columns.SingleOrDefault(x=>x.Name=="stanowisko");
                    if(col!=null){
                        if(!_dirtyColumns.Any(x=>x.Name==col.Name) && _isLoaded){
                            _dirtyColumns.Add(col);
                        }
                    }
                    OnChanged();
                }
            }
        }

        string _umowaOd;
        public string umowaOd
        {
            get { return _umowaOd; }
            set
            {
                if(_umowaOd!=value){
                    _umowaOd=value;
                    var col=tbl.Columns.SingleOrDefault(x=>x.Name=="umowaOd");
                    if(col!=null){
                        if(!_dirtyColumns.Any(x=>x.Name==col.Name) && _isLoaded){
                            _dirtyColumns.Add(col);
                        }
                    }
                    OnChanged();
                }
            }
        }

        string _umowaDo;
        public string umowaDo
        {
            get { return _umowaDo; }
            set
            {
                if(_umowaDo!=value){
                    _umowaDo=value;
                    var col=tbl.Columns.SingleOrDefault(x=>x.Name=="umowaDo");
                    if(col!=null){
                        if(!_dirtyColumns.Any(x=>x.Name==col.Name) && _isLoaded){
                            _dirtyColumns.Add(col);
                        }
                    }
                    OnChanged();
                }
            }
        }

        string _rozliczanie;
        public string rozliczanie
        {
            get { return _rozliczanie; }
            set
            {
                if(_rozliczanie!=value){
                    _rozliczanie=value;
                    var col=tbl.Columns.SingleOrDefault(x=>x.Name=="rozliczanie");
                    if(col!=null){
                        if(!_dirtyColumns.Any(x=>x.Name==col.Name) && _isLoaded){
                            _dirtyColumns.Add(col);
                        }
                    }
                    OnChanged();
                }
            }
        }

        string _trybZwolnienia;
        public string trybZwolnienia
        {
            get { return _trybZwolnienia; }
            set
            {
                if(_trybZwolnienia!=value){
                    _trybZwolnienia=value;
                    var col=tbl.Columns.SingleOrDefault(x=>x.Name=="trybZwolnienia");
                    if(col!=null){
                        if(!_dirtyColumns.Any(x=>x.Name==col.Name) && _isLoaded){
                            _dirtyColumns.Add(col);
                        }
                    }
                    OnChanged();
                }
            }
        }

        string _dataZwolnienia;
        public string dataZwolnienia
        {
            get { return _dataZwolnienia; }
            set
            {
                if(_dataZwolnienia!=value){
                    _dataZwolnienia=value;
                    var col=tbl.Columns.SingleOrDefault(x=>x.Name=="dataZwolnienia");
                    if(col!=null){
                        if(!_dirtyColumns.Any(x=>x.Name==col.Name) && _isLoaded){
                            _dirtyColumns.Add(col);
                        }
                    }
                    OnChanged();
                }
            }
        }

        string _zatrudnienieNa;
        public string zatrudnienieNa
        {
            get { return _zatrudnienieNa; }
            set
            {
                if(_zatrudnienieNa!=value){
                    _zatrudnienieNa=value;
                    var col=tbl.Columns.SingleOrDefault(x=>x.Name=="zatrudnienieNa");
                    if(col!=null){
                        if(!_dirtyColumns.Any(x=>x.Name==col.Name) && _isLoaded){
                            _dirtyColumns.Add(col);
                        }
                    }
                    OnChanged();
                }
            }
        }



        public DbCommand GetUpdateCommand() {
            if(TestMode)
                return _db.DataProvider.CreateCommand();
            else
                return this.ToUpdateQuery(_db.Provider).GetCommand().ToDbCommand();
            
        }
        public DbCommand GetInsertCommand() {
 
            if(TestMode)
                return _db.DataProvider.CreateCommand();
            else
                return this.ToInsertQuery(_db.Provider).GetCommand().ToDbCommand();
        }
        
        public DbCommand GetDeleteCommand() {
            if(TestMode)
                return _db.DataProvider.CreateCommand();
            else
                return this.ToDeleteQuery(_db.Provider).GetCommand().ToDbCommand();
        }
       
        
        public void Update(){
            Update(_db.DataProvider);
        }
        
        public void Update(IDataProvider provider){
        
            
            if(this._dirtyColumns.Count>0){
                _repo.Update(this,provider);
                _dirtyColumns.Clear();    
            }
            OnSaved();
       }
 
        public void Add(){
            Add(_db.DataProvider);
        }
        
        
       
        public void Add(IDataProvider provider){

            
            var key=KeyValue();
            if(key==null){
                var newKey=_repo.Add(this,provider);
                this.SetKeyValue(newKey);
            }else{
                _repo.Add(this,provider);
            }
            SetIsNew(false);
            OnSaved();
        }
        
                
        
        public void Save() {
            Save(_db.DataProvider);
        }      
        public void Save(IDataProvider provider) {
            
           
            if (_isNew) {
                Add(provider);
                
            } else {
                Update(provider);
            }
            
        }

        

        public void Delete(IDataProvider provider) {
                   
                 
            _repo.Delete(KeyValue());
            
                    }


        public void Delete() {
            Delete(_db.DataProvider);
        }


        public static void Delete(Expression<Func<Zatrudnienie, bool>> expression) {
            var repo = GetRepo();
            
       
            
            repo.DeleteMany(expression);
            
        }

        

        public void Load(IDataReader rdr) {
            Load(rdr, true);
        }
        public void Load(IDataReader rdr, bool closeReader) {
            if (rdr.Read()) {

                try {
                    rdr.Load(this);
                    SetIsNew(false);
                    SetIsLoaded(true);
                } catch {
                    SetIsLoaded(false);
                    throw;
                }
            }else{
                SetIsLoaded(false);
            }

            if (closeReader)
                rdr.Dispose();
        }
        

    } 
    
    
    /// <summary>
    /// A class which represents the ankieta table in the evolution Database.
    /// </summary>
    public partial class ankietum: IActiveRecord
    {
    
        #region Built-in testing
        static TestRepository<ankietum> _testRepo;
        

        
        static void SetTestRepo(){
            _testRepo = _testRepo ?? new TestRepository<ankietum>(new Amortyzacje.Model.evolutionDB());
        }
        public static void ResetTestRepo(){
            _testRepo = null;
            SetTestRepo();
        }
        public static void Setup(List<ankietum> testlist){
            SetTestRepo();
            foreach (var item in testlist)
            {
                _testRepo._items.Add(item);
            }
        }
        public static void Setup(ankietum item) {
            SetTestRepo();
            _testRepo._items.Add(item);
        }
        public static void Setup(int testItems) {
            SetTestRepo();
            for(int i=0;i<testItems;i++){
                ankietum item=new ankietum();
                _testRepo._items.Add(item);
            }
        }
        
        public bool TestMode = false;


        #endregion

        IRepository<ankietum> _repo;
        ITable tbl;
        bool _isNew;
        public bool IsNew(){
            return _isNew;
        }
        
        public void SetIsLoaded(bool isLoaded){
            _isLoaded=isLoaded;
            if(isLoaded)
                OnLoaded();
        }
        
        public void SetIsNew(bool isNew){
            _isNew=isNew;
        }
        bool _isLoaded;
        public bool IsLoaded(){
            return _isLoaded;
        }
                
        List<IColumn> _dirtyColumns;
        public bool IsDirty(){
            return _dirtyColumns.Count>0;
        }
        
        public List<IColumn> GetDirtyColumns (){
            return _dirtyColumns;
        }

        Amortyzacje.Model.evolutionDB _db;
        public ankietum(string connectionString, string providerName) {

            _db=new Amortyzacje.Model.evolutionDB(connectionString, providerName);
            Init();            
         }
        void Init(){
            TestMode=this._db.DataProvider.ConnectionString.Equals("test", StringComparison.InvariantCultureIgnoreCase);
            _dirtyColumns=new List<IColumn>();
            if(TestMode){
                ankietum.SetTestRepo();
                _repo=_testRepo;
            }else{
                _repo = new SubSonicRepository<ankietum>(_db);
            }
            tbl=_repo.GetTable();
            SetIsNew(true);
            OnCreated();       

        }
        
        public ankietum(){
             _db=new Amortyzacje.Model.evolutionDB();
            Init();            
        }
        
       
        partial void OnCreated();
            
        partial void OnLoaded();
        
        partial void OnSaved();
        
        partial void OnChanged();
        
        public IList<IColumn> Columns{
            get{
                return tbl.Columns;
            }
        }

        public ankietum(Expression<Func<ankietum, bool>> expression):this() {

            SetIsLoaded(_repo.Load(this,expression));
        }
        
       
        
        internal static IRepository<ankietum> GetRepo(string connectionString, string providerName){
            Amortyzacje.Model.evolutionDB db;
            if(String.IsNullOrEmpty(connectionString)){
                db=new Amortyzacje.Model.evolutionDB();
            }else{
                db=new Amortyzacje.Model.evolutionDB(connectionString, providerName);
            }
            IRepository<ankietum> _repo;
            
            if(db.TestMode){
                ankietum.SetTestRepo();
                _repo=_testRepo;
            }else{
                _repo = new SubSonicRepository<ankietum>(db);
            }
            return _repo;        
        }       
        
        internal static IRepository<ankietum> GetRepo(){
            return GetRepo("","");
        }
        
        public static ankietum SingleOrDefault(Expression<Func<ankietum, bool>> expression) {

            var repo = GetRepo();
            var results=repo.Find(expression);
            ankietum single=null;
            if(results.Count() > 0){
                single=results.ToList()[0];
                single.OnLoaded();
                single.SetIsLoaded(true);
                single.SetIsNew(false);
            }

            return single;
        }      
        
        public static ankietum SingleOrDefault(Expression<Func<ankietum, bool>> expression,string connectionString, string providerName) {
            var repo = GetRepo(connectionString,providerName);
            var results=repo.Find(expression);
            ankietum single=null;
            if(results.Count() > 0){
                single=results.ToList()[0];
            }

            return single;


        }
        
        
        public static bool Exists(Expression<Func<ankietum, bool>> expression,string connectionString, string providerName) {
           
            return All(connectionString,providerName).Any(expression);
        }        
        public static bool Exists(Expression<Func<ankietum, bool>> expression) {
           
            return All().Any(expression);
        }        

        public static IList<ankietum> Find(Expression<Func<ankietum, bool>> expression) {
            
            var repo = GetRepo();
            return repo.Find(expression).ToList();
        }
        
        public static IList<ankietum> Find(Expression<Func<ankietum, bool>> expression,string connectionString, string providerName) {

            var repo = GetRepo(connectionString,providerName);
            return repo.Find(expression).ToList();

        }
        public static IQueryable<ankietum> All(string connectionString, string providerName) {
            return GetRepo(connectionString,providerName).GetAll();
        }
        public static IQueryable<ankietum> All() {
            return GetRepo().GetAll();
        }
        
        public static PagedList<ankietum> GetPaged(string sortBy, int pageIndex, int pageSize,string connectionString, string providerName) {
            return GetRepo(connectionString,providerName).GetPaged(sortBy, pageIndex, pageSize);
        }
      
        public static PagedList<ankietum> GetPaged(string sortBy, int pageIndex, int pageSize) {
            return GetRepo().GetPaged(sortBy, pageIndex, pageSize);
        }

        public static PagedList<ankietum> GetPaged(int pageIndex, int pageSize,string connectionString, string providerName) {
            return GetRepo(connectionString,providerName).GetPaged(pageIndex, pageSize);
            
        }


        public static PagedList<ankietum> GetPaged(int pageIndex, int pageSize) {
            return GetRepo().GetPaged(pageIndex, pageSize);
            
        }

        public string KeyName()
        {
            return "idankieta";
        }

        public object KeyValue()
        {
            return this.idankieta;
        }
        
        public void SetKeyValue(object value) {
            if (value != null && value!=DBNull.Value) {
                var settable = value.ChangeTypeTo<int>();
                this.GetType().GetProperty(this.KeyName()).SetValue(this, settable, null);
            }
        }
        
        public override string ToString(){
                            return this.uwagi.ToString();
                    }

        public override bool Equals(object obj){
            if(obj.GetType()==typeof(ankietum)){
                ankietum compare=(ankietum)obj;
                return compare.KeyValue()==this.KeyValue();
            }else{
                return base.Equals(obj);
            }
        }

        
        public override int GetHashCode() {
            return this.idankieta;
        }
        
        public string DescriptorValue()
        {
                            return this.uwagi.ToString();
                    }

        public string DescriptorColumn() {
            return "uwagi";
        }
        public static string GetKeyColumn()
        {
            return "idankieta";
        }        
        public static string GetDescriptorColumn()
        {
            return "uwagi";
        }
        
        #region ' Foreign Keys '
        #endregion
        

        int _idankieta;
        public int idankieta
        {
            get { return _idankieta; }
            set
            {
                if(_idankieta!=value){
                    _idankieta=value;
                    var col=tbl.Columns.SingleOrDefault(x=>x.Name=="idankieta");
                    if(col!=null){
                        if(!_dirtyColumns.Any(x=>x.Name==col.Name) && _isLoaded){
                            _dirtyColumns.Add(col);
                        }
                    }
                    OnChanged();
                }
            }
        }

        long _id_klienta;
        public long id_klienta
        {
            get { return _id_klienta; }
            set
            {
                if(_id_klienta!=value){
                    _id_klienta=value;
                    var col=tbl.Columns.SingleOrDefault(x=>x.Name=="id_klienta");
                    if(col!=null){
                        if(!_dirtyColumns.Any(x=>x.Name==col.Name) && _isLoaded){
                            _dirtyColumns.Add(col);
                        }
                    }
                    OnChanged();
                }
            }
        }

        int _id_szkolenia;
        public int id_szkolenia
        {
            get { return _id_szkolenia; }
            set
            {
                if(_id_szkolenia!=value){
                    _id_szkolenia=value;
                    var col=tbl.Columns.SingleOrDefault(x=>x.Name=="id_szkolenia");
                    if(col!=null){
                        if(!_dirtyColumns.Any(x=>x.Name==col.Name) && _isLoaded){
                            _dirtyColumns.Add(col);
                        }
                    }
                    OnChanged();
                }
            }
        }

        int _v1;
        public int v1
        {
            get { return _v1; }
            set
            {
                if(_v1!=value){
                    _v1=value;
                    var col=tbl.Columns.SingleOrDefault(x=>x.Name=="v1");
                    if(col!=null){
                        if(!_dirtyColumns.Any(x=>x.Name==col.Name) && _isLoaded){
                            _dirtyColumns.Add(col);
                        }
                    }
                    OnChanged();
                }
            }
        }

        int _v2;
        public int v2
        {
            get { return _v2; }
            set
            {
                if(_v2!=value){
                    _v2=value;
                    var col=tbl.Columns.SingleOrDefault(x=>x.Name=="v2");
                    if(col!=null){
                        if(!_dirtyColumns.Any(x=>x.Name==col.Name) && _isLoaded){
                            _dirtyColumns.Add(col);
                        }
                    }
                    OnChanged();
                }
            }
        }

        int _v3;
        public int v3
        {
            get { return _v3; }
            set
            {
                if(_v3!=value){
                    _v3=value;
                    var col=tbl.Columns.SingleOrDefault(x=>x.Name=="v3");
                    if(col!=null){
                        if(!_dirtyColumns.Any(x=>x.Name==col.Name) && _isLoaded){
                            _dirtyColumns.Add(col);
                        }
                    }
                    OnChanged();
                }
            }
        }

        int _v4;
        public int v4
        {
            get { return _v4; }
            set
            {
                if(_v4!=value){
                    _v4=value;
                    var col=tbl.Columns.SingleOrDefault(x=>x.Name=="v4");
                    if(col!=null){
                        if(!_dirtyColumns.Any(x=>x.Name==col.Name) && _isLoaded){
                            _dirtyColumns.Add(col);
                        }
                    }
                    OnChanged();
                }
            }
        }

        int _v5;
        public int v5
        {
            get { return _v5; }
            set
            {
                if(_v5!=value){
                    _v5=value;
                    var col=tbl.Columns.SingleOrDefault(x=>x.Name=="v5");
                    if(col!=null){
                        if(!_dirtyColumns.Any(x=>x.Name==col.Name) && _isLoaded){
                            _dirtyColumns.Add(col);
                        }
                    }
                    OnChanged();
                }
            }
        }

        int _v6;
        public int v6
        {
            get { return _v6; }
            set
            {
                if(_v6!=value){
                    _v6=value;
                    var col=tbl.Columns.SingleOrDefault(x=>x.Name=="v6");
                    if(col!=null){
                        if(!_dirtyColumns.Any(x=>x.Name==col.Name) && _isLoaded){
                            _dirtyColumns.Add(col);
                        }
                    }
                    OnChanged();
                }
            }
        }

        int _v7;
        public int v7
        {
            get { return _v7; }
            set
            {
                if(_v7!=value){
                    _v7=value;
                    var col=tbl.Columns.SingleOrDefault(x=>x.Name=="v7");
                    if(col!=null){
                        if(!_dirtyColumns.Any(x=>x.Name==col.Name) && _isLoaded){
                            _dirtyColumns.Add(col);
                        }
                    }
                    OnChanged();
                }
            }
        }

        string _uwagi;
        public string uwagi
        {
            get { return _uwagi; }
            set
            {
                if(_uwagi!=value){
                    _uwagi=value;
                    var col=tbl.Columns.SingleOrDefault(x=>x.Name=="uwagi");
                    if(col!=null){
                        if(!_dirtyColumns.Any(x=>x.Name==col.Name) && _isLoaded){
                            _dirtyColumns.Add(col);
                        }
                    }
                    OnChanged();
                }
            }
        }



        public DbCommand GetUpdateCommand() {
            if(TestMode)
                return _db.DataProvider.CreateCommand();
            else
                return this.ToUpdateQuery(_db.Provider).GetCommand().ToDbCommand();
            
        }
        public DbCommand GetInsertCommand() {
 
            if(TestMode)
                return _db.DataProvider.CreateCommand();
            else
                return this.ToInsertQuery(_db.Provider).GetCommand().ToDbCommand();
        }
        
        public DbCommand GetDeleteCommand() {
            if(TestMode)
                return _db.DataProvider.CreateCommand();
            else
                return this.ToDeleteQuery(_db.Provider).GetCommand().ToDbCommand();
        }
       
        
        public void Update(){
            Update(_db.DataProvider);
        }
        
        public void Update(IDataProvider provider){
        
            
            if(this._dirtyColumns.Count>0){
                _repo.Update(this,provider);
                _dirtyColumns.Clear();    
            }
            OnSaved();
       }
 
        public void Add(){
            Add(_db.DataProvider);
        }
        
        
       
        public void Add(IDataProvider provider){

            
            var key=KeyValue();
            if(key==null){
                var newKey=_repo.Add(this,provider);
                this.SetKeyValue(newKey);
            }else{
                _repo.Add(this,provider);
            }
            SetIsNew(false);
            OnSaved();
        }
        
                
        
        public void Save() {
            Save(_db.DataProvider);
        }      
        public void Save(IDataProvider provider) {
            
           
            if (_isNew) {
                Add(provider);
                
            } else {
                Update(provider);
            }
            
        }

        

        public void Delete(IDataProvider provider) {
                   
                 
            _repo.Delete(KeyValue());
            
                    }


        public void Delete() {
            Delete(_db.DataProvider);
        }


        public static void Delete(Expression<Func<ankietum, bool>> expression) {
            var repo = GetRepo();
            
       
            
            repo.DeleteMany(expression);
            
        }

        

        public void Load(IDataReader rdr) {
            Load(rdr, true);
        }
        public void Load(IDataReader rdr, bool closeReader) {
            if (rdr.Read()) {

                try {
                    rdr.Load(this);
                    SetIsNew(false);
                    SetIsLoaded(true);
                } catch {
                    SetIsLoaded(false);
                    throw;
                }
            }else{
                SetIsLoaded(false);
            }

            if (closeReader)
                rdr.Dispose();
        }
        

    } 
    
    
    /// <summary>
    /// A class which represents the certyfikaty table in the evolution Database.
    /// </summary>
    public partial class certyfikaty: IActiveRecord
    {
    
        #region Built-in testing
        static TestRepository<certyfikaty> _testRepo;
        

        
        static void SetTestRepo(){
            _testRepo = _testRepo ?? new TestRepository<certyfikaty>(new Amortyzacje.Model.evolutionDB());
        }
        public static void ResetTestRepo(){
            _testRepo = null;
            SetTestRepo();
        }
        public static void Setup(List<certyfikaty> testlist){
            SetTestRepo();
            foreach (var item in testlist)
            {
                _testRepo._items.Add(item);
            }
        }
        public static void Setup(certyfikaty item) {
            SetTestRepo();
            _testRepo._items.Add(item);
        }
        public static void Setup(int testItems) {
            SetTestRepo();
            for(int i=0;i<testItems;i++){
                certyfikaty item=new certyfikaty();
                _testRepo._items.Add(item);
            }
        }
        
        public bool TestMode = false;


        #endregion

        IRepository<certyfikaty> _repo;
        ITable tbl;
        bool _isNew;
        public bool IsNew(){
            return _isNew;
        }
        
        public void SetIsLoaded(bool isLoaded){
            _isLoaded=isLoaded;
            if(isLoaded)
                OnLoaded();
        }
        
        public void SetIsNew(bool isNew){
            _isNew=isNew;
        }
        bool _isLoaded;
        public bool IsLoaded(){
            return _isLoaded;
        }
                
        List<IColumn> _dirtyColumns;
        public bool IsDirty(){
            return _dirtyColumns.Count>0;
        }
        
        public List<IColumn> GetDirtyColumns (){
            return _dirtyColumns;
        }

        Amortyzacje.Model.evolutionDB _db;
        public certyfikaty(string connectionString, string providerName) {

            _db=new Amortyzacje.Model.evolutionDB(connectionString, providerName);
            Init();            
         }
        void Init(){
            TestMode=this._db.DataProvider.ConnectionString.Equals("test", StringComparison.InvariantCultureIgnoreCase);
            _dirtyColumns=new List<IColumn>();
            if(TestMode){
                certyfikaty.SetTestRepo();
                _repo=_testRepo;
            }else{
                _repo = new SubSonicRepository<certyfikaty>(_db);
            }
            tbl=_repo.GetTable();
            SetIsNew(true);
            OnCreated();       

        }
        
        public certyfikaty(){
             _db=new Amortyzacje.Model.evolutionDB();
            Init();            
        }
        
       
        partial void OnCreated();
            
        partial void OnLoaded();
        
        partial void OnSaved();
        
        partial void OnChanged();
        
        public IList<IColumn> Columns{
            get{
                return tbl.Columns;
            }
        }

        public certyfikaty(Expression<Func<certyfikaty, bool>> expression):this() {

            SetIsLoaded(_repo.Load(this,expression));
        }
        
       
        
        internal static IRepository<certyfikaty> GetRepo(string connectionString, string providerName){
            Amortyzacje.Model.evolutionDB db;
            if(String.IsNullOrEmpty(connectionString)){
                db=new Amortyzacje.Model.evolutionDB();
            }else{
                db=new Amortyzacje.Model.evolutionDB(connectionString, providerName);
            }
            IRepository<certyfikaty> _repo;
            
            if(db.TestMode){
                certyfikaty.SetTestRepo();
                _repo=_testRepo;
            }else{
                _repo = new SubSonicRepository<certyfikaty>(db);
            }
            return _repo;        
        }       
        
        internal static IRepository<certyfikaty> GetRepo(){
            return GetRepo("","");
        }
        
        public static certyfikaty SingleOrDefault(Expression<Func<certyfikaty, bool>> expression) {

            var repo = GetRepo();
            var results=repo.Find(expression);
            certyfikaty single=null;
            if(results.Count() > 0){
                single=results.ToList()[0];
                single.OnLoaded();
                single.SetIsLoaded(true);
                single.SetIsNew(false);
            }

            return single;
        }      
        
        public static certyfikaty SingleOrDefault(Expression<Func<certyfikaty, bool>> expression,string connectionString, string providerName) {
            var repo = GetRepo(connectionString,providerName);
            var results=repo.Find(expression);
            certyfikaty single=null;
            if(results.Count() > 0){
                single=results.ToList()[0];
            }

            return single;


        }
        
        
        public static bool Exists(Expression<Func<certyfikaty, bool>> expression,string connectionString, string providerName) {
           
            return All(connectionString,providerName).Any(expression);
        }        
        public static bool Exists(Expression<Func<certyfikaty, bool>> expression) {
           
            return All().Any(expression);
        }        

        public static IList<certyfikaty> Find(Expression<Func<certyfikaty, bool>> expression) {
            
            var repo = GetRepo();
            return repo.Find(expression).ToList();
        }
        
        public static IList<certyfikaty> Find(Expression<Func<certyfikaty, bool>> expression,string connectionString, string providerName) {

            var repo = GetRepo(connectionString,providerName);
            return repo.Find(expression).ToList();

        }
        public static IQueryable<certyfikaty> All(string connectionString, string providerName) {
            return GetRepo(connectionString,providerName).GetAll();
        }
        public static IQueryable<certyfikaty> All() {
            return GetRepo().GetAll();
        }
        
        public static PagedList<certyfikaty> GetPaged(string sortBy, int pageIndex, int pageSize,string connectionString, string providerName) {
            return GetRepo(connectionString,providerName).GetPaged(sortBy, pageIndex, pageSize);
        }
      
        public static PagedList<certyfikaty> GetPaged(string sortBy, int pageIndex, int pageSize) {
            return GetRepo().GetPaged(sortBy, pageIndex, pageSize);
        }

        public static PagedList<certyfikaty> GetPaged(int pageIndex, int pageSize,string connectionString, string providerName) {
            return GetRepo(connectionString,providerName).GetPaged(pageIndex, pageSize);
            
        }


        public static PagedList<certyfikaty> GetPaged(int pageIndex, int pageSize) {
            return GetRepo().GetPaged(pageIndex, pageSize);
            
        }

        public string KeyName()
        {
            return "idcertyfikaty";
        }

        public object KeyValue()
        {
            return this.idcertyfikaty;
        }
        
        public void SetKeyValue(object value) {
            if (value != null && value!=DBNull.Value) {
                var settable = value.ChangeTypeTo<string>();
                this.GetType().GetProperty(this.KeyName()).SetValue(this, settable, null);
            }
        }
        
        public override string ToString(){
                            return this.idcertyfikaty.ToString();
                    }

        public override bool Equals(object obj){
            if(obj.GetType()==typeof(certyfikaty)){
                certyfikaty compare=(certyfikaty)obj;
                return compare.KeyValue()==this.KeyValue();
            }else{
                return base.Equals(obj);
            }
        }

        public string DescriptorValue()
        {
                            return this.idcertyfikaty.ToString();
                    }

        public string DescriptorColumn() {
            return "idcertyfikaty";
        }
        public static string GetKeyColumn()
        {
            return "idcertyfikaty";
        }        
        public static string GetDescriptorColumn()
        {
            return "idcertyfikaty";
        }
        
        #region ' Foreign Keys '
        #endregion
        

        string _idcertyfikaty;
        public string idcertyfikaty
        {
            get { return _idcertyfikaty; }
            set
            {
                if(_idcertyfikaty!=value){
                    _idcertyfikaty=value;
                    var col=tbl.Columns.SingleOrDefault(x=>x.Name=="idcertyfikaty");
                    if(col!=null){
                        if(!_dirtyColumns.Any(x=>x.Name==col.Name) && _isLoaded){
                            _dirtyColumns.Add(col);
                        }
                    }
                    OnChanged();
                }
            }
        }

        int _idszkolenie;
        public int idszkolenie
        {
            get { return _idszkolenie; }
            set
            {
                if(_idszkolenie!=value){
                    _idszkolenie=value;
                    var col=tbl.Columns.SingleOrDefault(x=>x.Name=="idszkolenie");
                    if(col!=null){
                        if(!_dirtyColumns.Any(x=>x.Name==col.Name) && _isLoaded){
                            _dirtyColumns.Add(col);
                        }
                    }
                    OnChanged();
                }
            }
        }

        int _iduczestnik;
        public int iduczestnik
        {
            get { return _iduczestnik; }
            set
            {
                if(_iduczestnik!=value){
                    _iduczestnik=value;
                    var col=tbl.Columns.SingleOrDefault(x=>x.Name=="iduczestnik");
                    if(col!=null){
                        if(!_dirtyColumns.Any(x=>x.Name==col.Name) && _isLoaded){
                            _dirtyColumns.Add(col);
                        }
                    }
                    OnChanged();
                }
            }
        }



        public DbCommand GetUpdateCommand() {
            if(TestMode)
                return _db.DataProvider.CreateCommand();
            else
                return this.ToUpdateQuery(_db.Provider).GetCommand().ToDbCommand();
            
        }
        public DbCommand GetInsertCommand() {
 
            if(TestMode)
                return _db.DataProvider.CreateCommand();
            else
                return this.ToInsertQuery(_db.Provider).GetCommand().ToDbCommand();
        }
        
        public DbCommand GetDeleteCommand() {
            if(TestMode)
                return _db.DataProvider.CreateCommand();
            else
                return this.ToDeleteQuery(_db.Provider).GetCommand().ToDbCommand();
        }
       
        
        public void Update(){
            Update(_db.DataProvider);
        }
        
        public void Update(IDataProvider provider){
        
            
            if(this._dirtyColumns.Count>0){
                _repo.Update(this,provider);
                _dirtyColumns.Clear();    
            }
            OnSaved();
       }
 
        public void Add(){
            Add(_db.DataProvider);
        }
        
        
       
        public void Add(IDataProvider provider){

            
            var key=KeyValue();
            if(key==null){
                var newKey=_repo.Add(this,provider);
                this.SetKeyValue(newKey);
            }else{
                _repo.Add(this,provider);
            }
            SetIsNew(false);
            OnSaved();
        }
        
                
        
        public void Save() {
            Save(_db.DataProvider);
        }      
        public void Save(IDataProvider provider) {
            
           
            if (_isNew) {
                Add(provider);
                
            } else {
                Update(provider);
            }
            
        }

        

        public void Delete(IDataProvider provider) {
                   
                 
            _repo.Delete(KeyValue());
            
                    }


        public void Delete() {
            Delete(_db.DataProvider);
        }


        public static void Delete(Expression<Func<certyfikaty, bool>> expression) {
            var repo = GetRepo();
            
       
            
            repo.DeleteMany(expression);
            
        }

        

        public void Load(IDataReader rdr) {
            Load(rdr, true);
        }
        public void Load(IDataReader rdr, bool closeReader) {
            if (rdr.Read()) {

                try {
                    rdr.Load(this);
                    SetIsNew(false);
                    SetIsLoaded(true);
                } catch {
                    SetIsLoaded(false);
                    throw;
                }
            }else{
                SetIsLoaded(false);
            }

            if (closeReader)
                rdr.Dispose();
        }
        

    } 
    
    
    /// <summary>
    /// A class which represents the faktury table in the evolution Database.
    /// </summary>
    public partial class faktury: IActiveRecord
    {
    
        #region Built-in testing
        static TestRepository<faktury> _testRepo;
        

        
        static void SetTestRepo(){
            _testRepo = _testRepo ?? new TestRepository<faktury>(new Amortyzacje.Model.evolutionDB());
        }
        public static void ResetTestRepo(){
            _testRepo = null;
            SetTestRepo();
        }
        public static void Setup(List<faktury> testlist){
            SetTestRepo();
            foreach (var item in testlist)
            {
                _testRepo._items.Add(item);
            }
        }
        public static void Setup(faktury item) {
            SetTestRepo();
            _testRepo._items.Add(item);
        }
        public static void Setup(int testItems) {
            SetTestRepo();
            for(int i=0;i<testItems;i++){
                faktury item=new faktury();
                _testRepo._items.Add(item);
            }
        }
        
        public bool TestMode = false;


        #endregion

        IRepository<faktury> _repo;
        ITable tbl;
        bool _isNew;
        public bool IsNew(){
            return _isNew;
        }
        
        public void SetIsLoaded(bool isLoaded){
            _isLoaded=isLoaded;
            if(isLoaded)
                OnLoaded();
        }
        
        public void SetIsNew(bool isNew){
            _isNew=isNew;
        }
        bool _isLoaded;
        public bool IsLoaded(){
            return _isLoaded;
        }
                
        List<IColumn> _dirtyColumns;
        public bool IsDirty(){
            return _dirtyColumns.Count>0;
        }
        
        public List<IColumn> GetDirtyColumns (){
            return _dirtyColumns;
        }

        Amortyzacje.Model.evolutionDB _db;
        public faktury(string connectionString, string providerName) {

            _db=new Amortyzacje.Model.evolutionDB(connectionString, providerName);
            Init();            
         }
        void Init(){
            TestMode=this._db.DataProvider.ConnectionString.Equals("test", StringComparison.InvariantCultureIgnoreCase);
            _dirtyColumns=new List<IColumn>();
            if(TestMode){
                faktury.SetTestRepo();
                _repo=_testRepo;
            }else{
                _repo = new SubSonicRepository<faktury>(_db);
            }
            tbl=_repo.GetTable();
            SetIsNew(true);
            OnCreated();       

        }
        
        public faktury(){
             _db=new Amortyzacje.Model.evolutionDB();
            Init();            
        }
        
       
        partial void OnCreated();
            
        partial void OnLoaded();
        
        partial void OnSaved();
        
        partial void OnChanged();
        
        public IList<IColumn> Columns{
            get{
                return tbl.Columns;
            }
        }

        public faktury(Expression<Func<faktury, bool>> expression):this() {

            SetIsLoaded(_repo.Load(this,expression));
        }
        
       
        
        internal static IRepository<faktury> GetRepo(string connectionString, string providerName){
            Amortyzacje.Model.evolutionDB db;
            if(String.IsNullOrEmpty(connectionString)){
                db=new Amortyzacje.Model.evolutionDB();
            }else{
                db=new Amortyzacje.Model.evolutionDB(connectionString, providerName);
            }
            IRepository<faktury> _repo;
            
            if(db.TestMode){
                faktury.SetTestRepo();
                _repo=_testRepo;
            }else{
                _repo = new SubSonicRepository<faktury>(db);
            }
            return _repo;        
        }       
        
        internal static IRepository<faktury> GetRepo(){
            return GetRepo("","");
        }
        
        public static faktury SingleOrDefault(Expression<Func<faktury, bool>> expression) {

            var repo = GetRepo();
            var results=repo.Find(expression);
            faktury single=null;
            if(results.Count() > 0){
                single=results.ToList()[0];
                single.OnLoaded();
                single.SetIsLoaded(true);
                single.SetIsNew(false);
            }

            return single;
        }      
        
        public static faktury SingleOrDefault(Expression<Func<faktury, bool>> expression,string connectionString, string providerName) {
            var repo = GetRepo(connectionString,providerName);
            var results=repo.Find(expression);
            faktury single=null;
            if(results.Count() > 0){
                single=results.ToList()[0];
            }

            return single;


        }
        
        
        public static bool Exists(Expression<Func<faktury, bool>> expression,string connectionString, string providerName) {
           
            return All(connectionString,providerName).Any(expression);
        }        
        public static bool Exists(Expression<Func<faktury, bool>> expression) {
           
            return All().Any(expression);
        }        

        public static IList<faktury> Find(Expression<Func<faktury, bool>> expression) {
            
            var repo = GetRepo();
            return repo.Find(expression).ToList();
        }
        
        public static IList<faktury> Find(Expression<Func<faktury, bool>> expression,string connectionString, string providerName) {

            var repo = GetRepo(connectionString,providerName);
            return repo.Find(expression).ToList();

        }
        public static IQueryable<faktury> All(string connectionString, string providerName) {
            return GetRepo(connectionString,providerName).GetAll();
        }
        public static IQueryable<faktury> All() {
            return GetRepo().GetAll();
        }
        
        public static PagedList<faktury> GetPaged(string sortBy, int pageIndex, int pageSize,string connectionString, string providerName) {
            return GetRepo(connectionString,providerName).GetPaged(sortBy, pageIndex, pageSize);
        }
      
        public static PagedList<faktury> GetPaged(string sortBy, int pageIndex, int pageSize) {
            return GetRepo().GetPaged(sortBy, pageIndex, pageSize);
        }

        public static PagedList<faktury> GetPaged(int pageIndex, int pageSize,string connectionString, string providerName) {
            return GetRepo(connectionString,providerName).GetPaged(pageIndex, pageSize);
            
        }


        public static PagedList<faktury> GetPaged(int pageIndex, int pageSize) {
            return GetRepo().GetPaged(pageIndex, pageSize);
            
        }

        public string KeyName()
        {
            return "id";
        }

        public object KeyValue()
        {
            return this.id;
        }
        
        public void SetKeyValue(object value) {
            if (value != null && value!=DBNull.Value) {
                var settable = value.ChangeTypeTo<ulong>();
                this.GetType().GetProperty(this.KeyName()).SetValue(this, settable, null);
            }
        }
        
        public override string ToString(){
                            return this.nr_faktury.ToString();
                    }

        public override bool Equals(object obj){
            if(obj.GetType()==typeof(faktury)){
                faktury compare=(faktury)obj;
                return compare.KeyValue()==this.KeyValue();
            }else{
                return base.Equals(obj);
            }
        }

        public string DescriptorValue()
        {
                            return this.nr_faktury.ToString();
                    }

        public string DescriptorColumn() {
            return "nr_faktury";
        }
        public static string GetKeyColumn()
        {
            return "id";
        }        
        public static string GetDescriptorColumn()
        {
            return "nr_faktury";
        }
        
        #region ' Foreign Keys '
        #endregion
        

        ulong _id;
        public ulong id
        {
            get { return _id; }
            set
            {
                if(_id!=value){
                    _id=value;
                    var col=tbl.Columns.SingleOrDefault(x=>x.Name=="id");
                    if(col!=null){
                        if(!_dirtyColumns.Any(x=>x.Name==col.Name) && _isLoaded){
                            _dirtyColumns.Add(col);
                        }
                    }
                    OnChanged();
                }
            }
        }

        string _nr_faktury;
        public string nr_faktury
        {
            get { return _nr_faktury; }
            set
            {
                if(_nr_faktury!=value){
                    _nr_faktury=value;
                    var col=tbl.Columns.SingleOrDefault(x=>x.Name=="nr_faktury");
                    if(col!=null){
                        if(!_dirtyColumns.Any(x=>x.Name==col.Name) && _isLoaded){
                            _dirtyColumns.Add(col);
                        }
                    }
                    OnChanged();
                }
            }
        }

        string _nazwa_sp;
        public string nazwa_sp
        {
            get { return _nazwa_sp; }
            set
            {
                if(_nazwa_sp!=value){
                    _nazwa_sp=value;
                    var col=tbl.Columns.SingleOrDefault(x=>x.Name=="nazwa_sp");
                    if(col!=null){
                        if(!_dirtyColumns.Any(x=>x.Name==col.Name) && _isLoaded){
                            _dirtyColumns.Add(col);
                        }
                    }
                    OnChanged();
                }
            }
        }

        string _adres_sp;
        public string adres_sp
        {
            get { return _adres_sp; }
            set
            {
                if(_adres_sp!=value){
                    _adres_sp=value;
                    var col=tbl.Columns.SingleOrDefault(x=>x.Name=="adres_sp");
                    if(col!=null){
                        if(!_dirtyColumns.Any(x=>x.Name==col.Name) && _isLoaded){
                            _dirtyColumns.Add(col);
                        }
                    }
                    OnChanged();
                }
            }
        }

        string _nip_sp;
        public string nip_sp
        {
            get { return _nip_sp; }
            set
            {
                if(_nip_sp!=value){
                    _nip_sp=value;
                    var col=tbl.Columns.SingleOrDefault(x=>x.Name=="nip_sp");
                    if(col!=null){
                        if(!_dirtyColumns.Any(x=>x.Name==col.Name) && _isLoaded){
                            _dirtyColumns.Add(col);
                        }
                    }
                    OnChanged();
                }
            }
        }

        string _nazwa_nb;
        public string nazwa_nb
        {
            get { return _nazwa_nb; }
            set
            {
                if(_nazwa_nb!=value){
                    _nazwa_nb=value;
                    var col=tbl.Columns.SingleOrDefault(x=>x.Name=="nazwa_nb");
                    if(col!=null){
                        if(!_dirtyColumns.Any(x=>x.Name==col.Name) && _isLoaded){
                            _dirtyColumns.Add(col);
                        }
                    }
                    OnChanged();
                }
            }
        }

        string _adres_nb;
        public string adres_nb
        {
            get { return _adres_nb; }
            set
            {
                if(_adres_nb!=value){
                    _adres_nb=value;
                    var col=tbl.Columns.SingleOrDefault(x=>x.Name=="adres_nb");
                    if(col!=null){
                        if(!_dirtyColumns.Any(x=>x.Name==col.Name) && _isLoaded){
                            _dirtyColumns.Add(col);
                        }
                    }
                    OnChanged();
                }
            }
        }

        string _nip_nb;
        public string nip_nb
        {
            get { return _nip_nb; }
            set
            {
                if(_nip_nb!=value){
                    _nip_nb=value;
                    var col=tbl.Columns.SingleOrDefault(x=>x.Name=="nip_nb");
                    if(col!=null){
                        if(!_dirtyColumns.Any(x=>x.Name==col.Name) && _isLoaded){
                            _dirtyColumns.Add(col);
                        }
                    }
                    OnChanged();
                }
            }
        }

        DateTime _data_wystawienia;
        public DateTime data_wystawienia
        {
            get { return _data_wystawienia; }
            set
            {
                if(_data_wystawienia!=value){
                    _data_wystawienia=value;
                    var col=tbl.Columns.SingleOrDefault(x=>x.Name=="data_wystawienia");
                    if(col!=null){
                        if(!_dirtyColumns.Any(x=>x.Name==col.Name) && _isLoaded){
                            _dirtyColumns.Add(col);
                        }
                    }
                    OnChanged();
                }
            }
        }

        DateTime _data_sprzedazy;
        public DateTime data_sprzedazy
        {
            get { return _data_sprzedazy; }
            set
            {
                if(_data_sprzedazy!=value){
                    _data_sprzedazy=value;
                    var col=tbl.Columns.SingleOrDefault(x=>x.Name=="data_sprzedazy");
                    if(col!=null){
                        if(!_dirtyColumns.Any(x=>x.Name==col.Name) && _isLoaded){
                            _dirtyColumns.Add(col);
                        }
                    }
                    OnChanged();
                }
            }
        }

        DateTime _termin_platnosci;
        public DateTime termin_platnosci
        {
            get { return _termin_platnosci; }
            set
            {
                if(_termin_platnosci!=value){
                    _termin_platnosci=value;
                    var col=tbl.Columns.SingleOrDefault(x=>x.Name=="termin_platnosci");
                    if(col!=null){
                        if(!_dirtyColumns.Any(x=>x.Name==col.Name) && _isLoaded){
                            _dirtyColumns.Add(col);
                        }
                    }
                    OnChanged();
                }
            }
        }

        string _id_pozycji;
        public string id_pozycji
        {
            get { return _id_pozycji; }
            set
            {
                if(_id_pozycji!=value){
                    _id_pozycji=value;
                    var col=tbl.Columns.SingleOrDefault(x=>x.Name=="id_pozycji");
                    if(col!=null){
                        if(!_dirtyColumns.Any(x=>x.Name==col.Name) && _isLoaded){
                            _dirtyColumns.Add(col);
                        }
                    }
                    OnChanged();
                }
            }
        }

        string _info_extra;
        public string info_extra
        {
            get { return _info_extra; }
            set
            {
                if(_info_extra!=value){
                    _info_extra=value;
                    var col=tbl.Columns.SingleOrDefault(x=>x.Name=="info_extra");
                    if(col!=null){
                        if(!_dirtyColumns.Any(x=>x.Name==col.Name) && _isLoaded){
                            _dirtyColumns.Add(col);
                        }
                    }
                    OnChanged();
                }
            }
        }

        decimal? _suma_do_zaplaty;
        public decimal? suma_do_zaplaty
        {
            get { return _suma_do_zaplaty; }
            set
            {
                if(_suma_do_zaplaty!=value){
                    _suma_do_zaplaty=value;
                    var col=tbl.Columns.SingleOrDefault(x=>x.Name=="suma_do_zaplaty");
                    if(col!=null){
                        if(!_dirtyColumns.Any(x=>x.Name==col.Name) && _isLoaded){
                            _dirtyColumns.Add(col);
                        }
                    }
                    OnChanged();
                }
            }
        }

        decimal? _zaplacone;
        public decimal? zaplacone
        {
            get { return _zaplacone; }
            set
            {
                if(_zaplacone!=value){
                    _zaplacone=value;
                    var col=tbl.Columns.SingleOrDefault(x=>x.Name=="zaplacone");
                    if(col!=null){
                        if(!_dirtyColumns.Any(x=>x.Name==col.Name) && _isLoaded){
                            _dirtyColumns.Add(col);
                        }
                    }
                    OnChanged();
                }
            }
        }

        string _forma_platnosci;
        public string forma_platnosci
        {
            get { return _forma_platnosci; }
            set
            {
                if(_forma_platnosci!=value){
                    _forma_platnosci=value;
                    var col=tbl.Columns.SingleOrDefault(x=>x.Name=="forma_platnosci");
                    if(col!=null){
                        if(!_dirtyColumns.Any(x=>x.Name==col.Name) && _isLoaded){
                            _dirtyColumns.Add(col);
                        }
                    }
                    OnChanged();
                }
            }
        }

        string _numer_konta;
        public string numer_konta
        {
            get { return _numer_konta; }
            set
            {
                if(_numer_konta!=value){
                    _numer_konta=value;
                    var col=tbl.Columns.SingleOrDefault(x=>x.Name=="numer_konta");
                    if(col!=null){
                        if(!_dirtyColumns.Any(x=>x.Name==col.Name) && _isLoaded){
                            _dirtyColumns.Add(col);
                        }
                    }
                    OnChanged();
                }
            }
        }



        public DbCommand GetUpdateCommand() {
            if(TestMode)
                return _db.DataProvider.CreateCommand();
            else
                return this.ToUpdateQuery(_db.Provider).GetCommand().ToDbCommand();
            
        }
        public DbCommand GetInsertCommand() {
 
            if(TestMode)
                return _db.DataProvider.CreateCommand();
            else
                return this.ToInsertQuery(_db.Provider).GetCommand().ToDbCommand();
        }
        
        public DbCommand GetDeleteCommand() {
            if(TestMode)
                return _db.DataProvider.CreateCommand();
            else
                return this.ToDeleteQuery(_db.Provider).GetCommand().ToDbCommand();
        }
       
        
        public void Update(){
            Update(_db.DataProvider);
        }
        
        public void Update(IDataProvider provider){
        
            
            if(this._dirtyColumns.Count>0){
                _repo.Update(this,provider);
                _dirtyColumns.Clear();    
            }
            OnSaved();
       }
 
        public void Add(){
            Add(_db.DataProvider);
        }
        
        
       
        public void Add(IDataProvider provider){

            
            var key=KeyValue();
            if(key==null){
                var newKey=_repo.Add(this,provider);
                this.SetKeyValue(newKey);
            }else{
                _repo.Add(this,provider);
            }
            SetIsNew(false);
            OnSaved();
        }
        
                
        
        public void Save() {
            Save(_db.DataProvider);
        }      
        public void Save(IDataProvider provider) {
            
           
            if (_isNew) {
                Add(provider);
                
            } else {
                Update(provider);
            }
            
        }

        

        public void Delete(IDataProvider provider) {
                   
                 
            _repo.Delete(KeyValue());
            
                    }


        public void Delete() {
            Delete(_db.DataProvider);
        }


        public static void Delete(Expression<Func<faktury, bool>> expression) {
            var repo = GetRepo();
            
       
            
            repo.DeleteMany(expression);
            
        }

        

        public void Load(IDataReader rdr) {
            Load(rdr, true);
        }
        public void Load(IDataReader rdr, bool closeReader) {
            if (rdr.Read()) {

                try {
                    rdr.Load(this);
                    SetIsNew(false);
                    SetIsLoaded(true);
                } catch {
                    SetIsLoaded(false);
                    throw;
                }
            }else{
                SetIsLoaded(false);
            }

            if (closeReader)
                rdr.Dispose();
        }
        

    } 
    
    
    /// <summary>
    /// A class which represents the gm_kst table in the evolution Database.
    /// </summary>
    public partial class gm_kst: IActiveRecord
    {
    
        #region Built-in testing
        static TestRepository<gm_kst> _testRepo;
        

        
        static void SetTestRepo(){
            _testRepo = _testRepo ?? new TestRepository<gm_kst>(new Amortyzacje.Model.evolutionDB());
        }
        public static void ResetTestRepo(){
            _testRepo = null;
            SetTestRepo();
        }
        public static void Setup(List<gm_kst> testlist){
            SetTestRepo();
            foreach (var item in testlist)
            {
                _testRepo._items.Add(item);
            }
        }
        public static void Setup(gm_kst item) {
            SetTestRepo();
            _testRepo._items.Add(item);
        }
        public static void Setup(int testItems) {
            SetTestRepo();
            for(int i=0;i<testItems;i++){
                gm_kst item=new gm_kst();
                _testRepo._items.Add(item);
            }
        }
        
        public bool TestMode = false;


        #endregion

        IRepository<gm_kst> _repo;
        ITable tbl;
        bool _isNew;
        public bool IsNew(){
            return _isNew;
        }
        
        public void SetIsLoaded(bool isLoaded){
            _isLoaded=isLoaded;
            if(isLoaded)
                OnLoaded();
        }
        
        public void SetIsNew(bool isNew){
            _isNew=isNew;
        }
        bool _isLoaded;
        public bool IsLoaded(){
            return _isLoaded;
        }
                
        List<IColumn> _dirtyColumns;
        public bool IsDirty(){
            return _dirtyColumns.Count>0;
        }
        
        public List<IColumn> GetDirtyColumns (){
            return _dirtyColumns;
        }

        Amortyzacje.Model.evolutionDB _db;
        public gm_kst(string connectionString, string providerName) {

            _db=new Amortyzacje.Model.evolutionDB(connectionString, providerName);
            Init();            
         }
        void Init(){
            TestMode=this._db.DataProvider.ConnectionString.Equals("test", StringComparison.InvariantCultureIgnoreCase);
            _dirtyColumns=new List<IColumn>();
            if(TestMode){
                gm_kst.SetTestRepo();
                _repo=_testRepo;
            }else{
                _repo = new SubSonicRepository<gm_kst>(_db);
            }
            tbl=_repo.GetTable();
            SetIsNew(true);
            OnCreated();       

        }
        
        public gm_kst(){
             _db=new Amortyzacje.Model.evolutionDB();
            Init();            
        }
        
       
        partial void OnCreated();
            
        partial void OnLoaded();
        
        partial void OnSaved();
        
        partial void OnChanged();
        
        public IList<IColumn> Columns{
            get{
                return tbl.Columns;
            }
        }

        public gm_kst(Expression<Func<gm_kst, bool>> expression):this() {

            SetIsLoaded(_repo.Load(this,expression));
        }
        
       
        
        internal static IRepository<gm_kst> GetRepo(string connectionString, string providerName){
            Amortyzacje.Model.evolutionDB db;
            if(String.IsNullOrEmpty(connectionString)){
                db=new Amortyzacje.Model.evolutionDB();
            }else{
                db=new Amortyzacje.Model.evolutionDB(connectionString, providerName);
            }
            IRepository<gm_kst> _repo;
            
            if(db.TestMode){
                gm_kst.SetTestRepo();
                _repo=_testRepo;
            }else{
                _repo = new SubSonicRepository<gm_kst>(db);
            }
            return _repo;        
        }       
        
        internal static IRepository<gm_kst> GetRepo(){
            return GetRepo("","");
        }
        
        public static gm_kst SingleOrDefault(Expression<Func<gm_kst, bool>> expression) {

            var repo = GetRepo();
            var results=repo.Find(expression);
            gm_kst single=null;
            if(results.Count() > 0){
                single=results.ToList()[0];
                single.OnLoaded();
                single.SetIsLoaded(true);
                single.SetIsNew(false);
            }

            return single;
        }      
        
        public static gm_kst SingleOrDefault(Expression<Func<gm_kst, bool>> expression,string connectionString, string providerName) {
            var repo = GetRepo(connectionString,providerName);
            var results=repo.Find(expression);
            gm_kst single=null;
            if(results.Count() > 0){
                single=results.ToList()[0];
            }

            return single;


        }
        
        
        public static bool Exists(Expression<Func<gm_kst, bool>> expression,string connectionString, string providerName) {
           
            return All(connectionString,providerName).Any(expression);
        }        
        public static bool Exists(Expression<Func<gm_kst, bool>> expression) {
           
            return All().Any(expression);
        }        

        public static IList<gm_kst> Find(Expression<Func<gm_kst, bool>> expression) {
            
            var repo = GetRepo();
            return repo.Find(expression).ToList();
        }
        
        public static IList<gm_kst> Find(Expression<Func<gm_kst, bool>> expression,string connectionString, string providerName) {

            var repo = GetRepo(connectionString,providerName);
            return repo.Find(expression).ToList();

        }
        public static IQueryable<gm_kst> All(string connectionString, string providerName) {
            return GetRepo(connectionString,providerName).GetAll();
        }
        public static IQueryable<gm_kst> All() {
            return GetRepo().GetAll();
        }
        
        public static PagedList<gm_kst> GetPaged(string sortBy, int pageIndex, int pageSize,string connectionString, string providerName) {
            return GetRepo(connectionString,providerName).GetPaged(sortBy, pageIndex, pageSize);
        }
      
        public static PagedList<gm_kst> GetPaged(string sortBy, int pageIndex, int pageSize) {
            return GetRepo().GetPaged(sortBy, pageIndex, pageSize);
        }

        public static PagedList<gm_kst> GetPaged(int pageIndex, int pageSize,string connectionString, string providerName) {
            return GetRepo(connectionString,providerName).GetPaged(pageIndex, pageSize);
            
        }


        public static PagedList<gm_kst> GetPaged(int pageIndex, int pageSize) {
            return GetRepo().GetPaged(pageIndex, pageSize);
            
        }

        public string KeyName()
        {
            return "kod";
        }

        public object KeyValue()
        {
            return this.kod;
        }
        
        public void SetKeyValue(object value) {
            if (value != null && value!=DBNull.Value) {
                var settable = value.ChangeTypeTo<int>();
                this.GetType().GetProperty(this.KeyName()).SetValue(this, settable, null);
            }
        }
        
        public override string ToString(){
                            return this.nazwa.ToString();
                    }

        public override bool Equals(object obj){
            if(obj.GetType()==typeof(gm_kst)){
                gm_kst compare=(gm_kst)obj;
                return compare.KeyValue()==this.KeyValue();
            }else{
                return base.Equals(obj);
            }
        }

        
        public override int GetHashCode() {
            return this.kod;
        }
        
        public string DescriptorValue()
        {
                            return this.nazwa.ToString();
                    }

        public string DescriptorColumn() {
            return "nazwa";
        }
        public static string GetKeyColumn()
        {
            return "kod";
        }        
        public static string GetDescriptorColumn()
        {
            return "nazwa";
        }
        
        #region ' Foreign Keys '
        #endregion
        

        int _kod;
        public int kod
        {
            get { return _kod; }
            set
            {
                if(_kod!=value){
                    _kod=value;
                    var col=tbl.Columns.SingleOrDefault(x=>x.Name=="kod");
                    if(col!=null){
                        if(!_dirtyColumns.Any(x=>x.Name==col.Name) && _isLoaded){
                            _dirtyColumns.Add(col);
                        }
                    }
                    OnChanged();
                }
            }
        }

        string _nazwa;
        public string nazwa
        {
            get { return _nazwa; }
            set
            {
                if(_nazwa!=value){
                    _nazwa=value;
                    var col=tbl.Columns.SingleOrDefault(x=>x.Name=="nazwa");
                    if(col!=null){
                        if(!_dirtyColumns.Any(x=>x.Name==col.Name) && _isLoaded){
                            _dirtyColumns.Add(col);
                        }
                    }
                    OnChanged();
                }
            }
        }

        double _stawka;
        public double stawka
        {
            get { return _stawka; }
            set
            {
                if(_stawka!=value){
                    _stawka=value;
                    var col=tbl.Columns.SingleOrDefault(x=>x.Name=="stawka");
                    if(col!=null){
                        if(!_dirtyColumns.Any(x=>x.Name==col.Name) && _isLoaded){
                            _dirtyColumns.Add(col);
                        }
                    }
                    OnChanged();
                }
            }
        }



        public DbCommand GetUpdateCommand() {
            if(TestMode)
                return _db.DataProvider.CreateCommand();
            else
                return this.ToUpdateQuery(_db.Provider).GetCommand().ToDbCommand();
            
        }
        public DbCommand GetInsertCommand() {
 
            if(TestMode)
                return _db.DataProvider.CreateCommand();
            else
                return this.ToInsertQuery(_db.Provider).GetCommand().ToDbCommand();
        }
        
        public DbCommand GetDeleteCommand() {
            if(TestMode)
                return _db.DataProvider.CreateCommand();
            else
                return this.ToDeleteQuery(_db.Provider).GetCommand().ToDbCommand();
        }
       
        
        public void Update(){
            Update(_db.DataProvider);
        }
        
        public void Update(IDataProvider provider){
        
            
            if(this._dirtyColumns.Count>0){
                _repo.Update(this,provider);
                _dirtyColumns.Clear();    
            }
            OnSaved();
       }
 
        public void Add(){
            Add(_db.DataProvider);
        }
        
        
       
        public void Add(IDataProvider provider){

            
            var key=KeyValue();
            if(key==null){
                var newKey=_repo.Add(this,provider);
                this.SetKeyValue(newKey);
            }else{
                _repo.Add(this,provider);
            }
            SetIsNew(false);
            OnSaved();
        }
        
                
        
        public void Save() {
            Save(_db.DataProvider);
        }      
        public void Save(IDataProvider provider) {
            
           
            if (_isNew) {
                Add(provider);
                
            } else {
                Update(provider);
            }
            
        }

        

        public void Delete(IDataProvider provider) {
                   
                 
            _repo.Delete(KeyValue());
            
                    }


        public void Delete() {
            Delete(_db.DataProvider);
        }


        public static void Delete(Expression<Func<gm_kst, bool>> expression) {
            var repo = GetRepo();
            
       
            
            repo.DeleteMany(expression);
            
        }

        

        public void Load(IDataReader rdr) {
            Load(rdr, true);
        }
        public void Load(IDataReader rdr, bool closeReader) {
            if (rdr.Read()) {

                try {
                    rdr.Load(this);
                    SetIsNew(false);
                    SetIsLoaded(true);
                } catch {
                    SetIsLoaded(false);
                    throw;
                }
            }else{
                SetIsLoaded(false);
            }

            if (closeReader)
                rdr.Dispose();
        }
        

    } 
    
    
    /// <summary>
    /// A class which represents the gm_materialy table in the evolution Database.
    /// </summary>
    public partial class gm_materialy: IActiveRecord
    {
    
        #region Built-in testing
        static TestRepository<gm_materialy> _testRepo;
        

        
        static void SetTestRepo(){
            _testRepo = _testRepo ?? new TestRepository<gm_materialy>(new Amortyzacje.Model.evolutionDB());
        }
        public static void ResetTestRepo(){
            _testRepo = null;
            SetTestRepo();
        }
        public static void Setup(List<gm_materialy> testlist){
            SetTestRepo();
            foreach (var item in testlist)
            {
                _testRepo._items.Add(item);
            }
        }
        public static void Setup(gm_materialy item) {
            SetTestRepo();
            _testRepo._items.Add(item);
        }
        public static void Setup(int testItems) {
            SetTestRepo();
            for(int i=0;i<testItems;i++){
                gm_materialy item=new gm_materialy();
                _testRepo._items.Add(item);
            }
        }
        
        public bool TestMode = false;


        #endregion

        IRepository<gm_materialy> _repo;
        ITable tbl;
        bool _isNew;
        public bool IsNew(){
            return _isNew;
        }
        
        public void SetIsLoaded(bool isLoaded){
            _isLoaded=isLoaded;
            if(isLoaded)
                OnLoaded();
        }
        
        public void SetIsNew(bool isNew){
            _isNew=isNew;
        }
        bool _isLoaded;
        public bool IsLoaded(){
            return _isLoaded;
        }
                
        List<IColumn> _dirtyColumns;
        public bool IsDirty(){
            return _dirtyColumns.Count>0;
        }
        
        public List<IColumn> GetDirtyColumns (){
            return _dirtyColumns;
        }

        Amortyzacje.Model.evolutionDB _db;
        public gm_materialy(string connectionString, string providerName) {

            _db=new Amortyzacje.Model.evolutionDB(connectionString, providerName);
            Init();            
         }
        void Init(){
            TestMode=this._db.DataProvider.ConnectionString.Equals("test", StringComparison.InvariantCultureIgnoreCase);
            _dirtyColumns=new List<IColumn>();
            if(TestMode){
                gm_materialy.SetTestRepo();
                _repo=_testRepo;
            }else{
                _repo = new SubSonicRepository<gm_materialy>(_db);
            }
            tbl=_repo.GetTable();
            SetIsNew(true);
            OnCreated();       

        }
        
        public gm_materialy(){
             _db=new Amortyzacje.Model.evolutionDB();
            Init();            
        }
        
       
        partial void OnCreated();
            
        partial void OnLoaded();
        
        partial void OnSaved();
        
        partial void OnChanged();
        
        public IList<IColumn> Columns{
            get{
                return tbl.Columns;
            }
        }

        public gm_materialy(Expression<Func<gm_materialy, bool>> expression):this() {

            SetIsLoaded(_repo.Load(this,expression));
        }
        
       
        
        internal static IRepository<gm_materialy> GetRepo(string connectionString, string providerName){
            Amortyzacje.Model.evolutionDB db;
            if(String.IsNullOrEmpty(connectionString)){
                db=new Amortyzacje.Model.evolutionDB();
            }else{
                db=new Amortyzacje.Model.evolutionDB(connectionString, providerName);
            }
            IRepository<gm_materialy> _repo;
            
            if(db.TestMode){
                gm_materialy.SetTestRepo();
                _repo=_testRepo;
            }else{
                _repo = new SubSonicRepository<gm_materialy>(db);
            }
            return _repo;        
        }       
        
        internal static IRepository<gm_materialy> GetRepo(){
            return GetRepo("","");
        }
        
        public static gm_materialy SingleOrDefault(Expression<Func<gm_materialy, bool>> expression) {

            var repo = GetRepo();
            var results=repo.Find(expression);
            gm_materialy single=null;
            if(results.Count() > 0){
                single=results.ToList()[0];
                single.OnLoaded();
                single.SetIsLoaded(true);
                single.SetIsNew(false);
            }

            return single;
        }      
        
        public static gm_materialy SingleOrDefault(Expression<Func<gm_materialy, bool>> expression,string connectionString, string providerName) {
            var repo = GetRepo(connectionString,providerName);
            var results=repo.Find(expression);
            gm_materialy single=null;
            if(results.Count() > 0){
                single=results.ToList()[0];
            }

            return single;


        }
        
        
        public static bool Exists(Expression<Func<gm_materialy, bool>> expression,string connectionString, string providerName) {
           
            return All(connectionString,providerName).Any(expression);
        }        
        public static bool Exists(Expression<Func<gm_materialy, bool>> expression) {
           
            return All().Any(expression);
        }        

        public static IList<gm_materialy> Find(Expression<Func<gm_materialy, bool>> expression) {
            
            var repo = GetRepo();
            return repo.Find(expression).ToList();
        }
        
        public static IList<gm_materialy> Find(Expression<Func<gm_materialy, bool>> expression,string connectionString, string providerName) {

            var repo = GetRepo(connectionString,providerName);
            return repo.Find(expression).ToList();

        }
        public static IQueryable<gm_materialy> All(string connectionString, string providerName) {
            return GetRepo(connectionString,providerName).GetAll();
        }
        public static IQueryable<gm_materialy> All() {
            return GetRepo().GetAll();
        }
        
        public static PagedList<gm_materialy> GetPaged(string sortBy, int pageIndex, int pageSize,string connectionString, string providerName) {
            return GetRepo(connectionString,providerName).GetPaged(sortBy, pageIndex, pageSize);
        }
      
        public static PagedList<gm_materialy> GetPaged(string sortBy, int pageIndex, int pageSize) {
            return GetRepo().GetPaged(sortBy, pageIndex, pageSize);
        }

        public static PagedList<gm_materialy> GetPaged(int pageIndex, int pageSize,string connectionString, string providerName) {
            return GetRepo(connectionString,providerName).GetPaged(pageIndex, pageSize);
            
        }


        public static PagedList<gm_materialy> GetPaged(int pageIndex, int pageSize) {
            return GetRepo().GetPaged(pageIndex, pageSize);
            
        }

        public string KeyName()
        {
            return "id";
        }

        public object KeyValue()
        {
            return this.id;
        }
        
        public void SetKeyValue(object value) {
            if (value != null && value!=DBNull.Value) {
                var settable = value.ChangeTypeTo<int>();
                this.GetType().GetProperty(this.KeyName()).SetValue(this, settable, null);
            }
        }
        
        public override string ToString(){
                            return this.nazwa.ToString();
                    }

        public override bool Equals(object obj){
            if(obj.GetType()==typeof(gm_materialy)){
                gm_materialy compare=(gm_materialy)obj;
                return compare.KeyValue()==this.KeyValue();
            }else{
                return base.Equals(obj);
            }
        }

        
        public override int GetHashCode() {
            return this.id;
        }
        
        public string DescriptorValue()
        {
                            return this.nazwa.ToString();
                    }

        public string DescriptorColumn() {
            return "nazwa";
        }
        public static string GetKeyColumn()
        {
            return "id";
        }        
        public static string GetDescriptorColumn()
        {
            return "nazwa";
        }
        
        #region ' Foreign Keys '
        #endregion
        

        int _id;
        public int id
        {
            get { return _id; }
            set
            {
                if(_id!=value){
                    _id=value;
                    var col=tbl.Columns.SingleOrDefault(x=>x.Name=="id");
                    if(col!=null){
                        if(!_dirtyColumns.Any(x=>x.Name==col.Name) && _isLoaded){
                            _dirtyColumns.Add(col);
                        }
                    }
                    OnChanged();
                }
            }
        }

        uint _ilosc;
        public uint ilosc
        {
            get { return _ilosc; }
            set
            {
                if(_ilosc!=value){
                    _ilosc=value;
                    var col=tbl.Columns.SingleOrDefault(x=>x.Name=="ilosc");
                    if(col!=null){
                        if(!_dirtyColumns.Any(x=>x.Name==col.Name) && _isLoaded){
                            _dirtyColumns.Add(col);
                        }
                    }
                    OnChanged();
                }
            }
        }

        string _nazwa;
        public string nazwa
        {
            get { return _nazwa; }
            set
            {
                if(_nazwa!=value){
                    _nazwa=value;
                    var col=tbl.Columns.SingleOrDefault(x=>x.Name=="nazwa");
                    if(col!=null){
                        if(!_dirtyColumns.Any(x=>x.Name==col.Name) && _isLoaded){
                            _dirtyColumns.Add(col);
                        }
                    }
                    OnChanged();
                }
            }
        }

        int _wartosc_egzemplarza;
        public int wartosc_egzemplarza
        {
            get { return _wartosc_egzemplarza; }
            set
            {
                if(_wartosc_egzemplarza!=value){
                    _wartosc_egzemplarza=value;
                    var col=tbl.Columns.SingleOrDefault(x=>x.Name=="wartosc_egzemplarza");
                    if(col!=null){
                        if(!_dirtyColumns.Any(x=>x.Name==col.Name) && _isLoaded){
                            _dirtyColumns.Add(col);
                        }
                    }
                    OnChanged();
                }
            }
        }

        uint _min;
        public uint min
        {
            get { return _min; }
            set
            {
                if(_min!=value){
                    _min=value;
                    var col=tbl.Columns.SingleOrDefault(x=>x.Name=="min");
                    if(col!=null){
                        if(!_dirtyColumns.Any(x=>x.Name==col.Name) && _isLoaded){
                            _dirtyColumns.Add(col);
                        }
                    }
                    OnChanged();
                }
            }
        }

        uint _max;
        public uint max
        {
            get { return _max; }
            set
            {
                if(_max!=value){
                    _max=value;
                    var col=tbl.Columns.SingleOrDefault(x=>x.Name=="max");
                    if(col!=null){
                        if(!_dirtyColumns.Any(x=>x.Name==col.Name) && _isLoaded){
                            _dirtyColumns.Add(col);
                        }
                    }
                    OnChanged();
                }
            }
        }



        public DbCommand GetUpdateCommand() {
            if(TestMode)
                return _db.DataProvider.CreateCommand();
            else
                return this.ToUpdateQuery(_db.Provider).GetCommand().ToDbCommand();
            
        }
        public DbCommand GetInsertCommand() {
 
            if(TestMode)
                return _db.DataProvider.CreateCommand();
            else
                return this.ToInsertQuery(_db.Provider).GetCommand().ToDbCommand();
        }
        
        public DbCommand GetDeleteCommand() {
            if(TestMode)
                return _db.DataProvider.CreateCommand();
            else
                return this.ToDeleteQuery(_db.Provider).GetCommand().ToDbCommand();
        }
       
        
        public void Update(){
            Update(_db.DataProvider);
        }
        
        public void Update(IDataProvider provider){
        
            
            if(this._dirtyColumns.Count>0){
                _repo.Update(this,provider);
                _dirtyColumns.Clear();    
            }
            OnSaved();
       }
 
        public void Add(){
            Add(_db.DataProvider);
        }
        
        
       
        public void Add(IDataProvider provider){

            
            var key=KeyValue();
            if(key==null){
                var newKey=_repo.Add(this,provider);
                this.SetKeyValue(newKey);
            }else{
                _repo.Add(this,provider);
            }
            SetIsNew(false);
            OnSaved();
        }
        
                
        
        public void Save() {
            Save(_db.DataProvider);
        }      
        public void Save(IDataProvider provider) {
            
           
            if (_isNew) {
                Add(provider);
                
            } else {
                Update(provider);
            }
            
        }

        

        public void Delete(IDataProvider provider) {
                   
                 
            _repo.Delete(KeyValue());
            
                    }


        public void Delete() {
            Delete(_db.DataProvider);
        }


        public static void Delete(Expression<Func<gm_materialy, bool>> expression) {
            var repo = GetRepo();
            
       
            
            repo.DeleteMany(expression);
            
        }

        

        public void Load(IDataReader rdr) {
            Load(rdr, true);
        }
        public void Load(IDataReader rdr, bool closeReader) {
            if (rdr.Read()) {

                try {
                    rdr.Load(this);
                    SetIsNew(false);
                    SetIsLoaded(true);
                } catch {
                    SetIsLoaded(false);
                    throw;
                }
            }else{
                SetIsLoaded(false);
            }

            if (closeReader)
                rdr.Dispose();
        }
        

    } 
    
    
    /// <summary>
    /// A class which represents the gm_materialy_ruchy table in the evolution Database.
    /// </summary>
    public partial class gm_materialy_ruchy: IActiveRecord
    {
    
        #region Built-in testing
        static TestRepository<gm_materialy_ruchy> _testRepo;
        

        
        static void SetTestRepo(){
            _testRepo = _testRepo ?? new TestRepository<gm_materialy_ruchy>(new Amortyzacje.Model.evolutionDB());
        }
        public static void ResetTestRepo(){
            _testRepo = null;
            SetTestRepo();
        }
        public static void Setup(List<gm_materialy_ruchy> testlist){
            SetTestRepo();
            foreach (var item in testlist)
            {
                _testRepo._items.Add(item);
            }
        }
        public static void Setup(gm_materialy_ruchy item) {
            SetTestRepo();
            _testRepo._items.Add(item);
        }
        public static void Setup(int testItems) {
            SetTestRepo();
            for(int i=0;i<testItems;i++){
                gm_materialy_ruchy item=new gm_materialy_ruchy();
                _testRepo._items.Add(item);
            }
        }
        
        public bool TestMode = false;


        #endregion

        IRepository<gm_materialy_ruchy> _repo;
        ITable tbl;
        bool _isNew;
        public bool IsNew(){
            return _isNew;
        }
        
        public void SetIsLoaded(bool isLoaded){
            _isLoaded=isLoaded;
            if(isLoaded)
                OnLoaded();
        }
        
        public void SetIsNew(bool isNew){
            _isNew=isNew;
        }
        bool _isLoaded;
        public bool IsLoaded(){
            return _isLoaded;
        }
                
        List<IColumn> _dirtyColumns;
        public bool IsDirty(){
            return _dirtyColumns.Count>0;
        }
        
        public List<IColumn> GetDirtyColumns (){
            return _dirtyColumns;
        }

        Amortyzacje.Model.evolutionDB _db;
        public gm_materialy_ruchy(string connectionString, string providerName) {

            _db=new Amortyzacje.Model.evolutionDB(connectionString, providerName);
            Init();            
         }
        void Init(){
            TestMode=this._db.DataProvider.ConnectionString.Equals("test", StringComparison.InvariantCultureIgnoreCase);
            _dirtyColumns=new List<IColumn>();
            if(TestMode){
                gm_materialy_ruchy.SetTestRepo();
                _repo=_testRepo;
            }else{
                _repo = new SubSonicRepository<gm_materialy_ruchy>(_db);
            }
            tbl=_repo.GetTable();
            SetIsNew(true);
            OnCreated();       

        }
        
        public gm_materialy_ruchy(){
             _db=new Amortyzacje.Model.evolutionDB();
            Init();            
        }
        
       
        partial void OnCreated();
            
        partial void OnLoaded();
        
        partial void OnSaved();
        
        partial void OnChanged();
        
        public IList<IColumn> Columns{
            get{
                return tbl.Columns;
            }
        }

        public gm_materialy_ruchy(Expression<Func<gm_materialy_ruchy, bool>> expression):this() {

            SetIsLoaded(_repo.Load(this,expression));
        }
        
       
        
        internal static IRepository<gm_materialy_ruchy> GetRepo(string connectionString, string providerName){
            Amortyzacje.Model.evolutionDB db;
            if(String.IsNullOrEmpty(connectionString)){
                db=new Amortyzacje.Model.evolutionDB();
            }else{
                db=new Amortyzacje.Model.evolutionDB(connectionString, providerName);
            }
            IRepository<gm_materialy_ruchy> _repo;
            
            if(db.TestMode){
                gm_materialy_ruchy.SetTestRepo();
                _repo=_testRepo;
            }else{
                _repo = new SubSonicRepository<gm_materialy_ruchy>(db);
            }
            return _repo;        
        }       
        
        internal static IRepository<gm_materialy_ruchy> GetRepo(){
            return GetRepo("","");
        }
        
        public static gm_materialy_ruchy SingleOrDefault(Expression<Func<gm_materialy_ruchy, bool>> expression) {

            var repo = GetRepo();
            var results=repo.Find(expression);
            gm_materialy_ruchy single=null;
            if(results.Count() > 0){
                single=results.ToList()[0];
                single.OnLoaded();
                single.SetIsLoaded(true);
                single.SetIsNew(false);
            }

            return single;
        }      
        
        public static gm_materialy_ruchy SingleOrDefault(Expression<Func<gm_materialy_ruchy, bool>> expression,string connectionString, string providerName) {
            var repo = GetRepo(connectionString,providerName);
            var results=repo.Find(expression);
            gm_materialy_ruchy single=null;
            if(results.Count() > 0){
                single=results.ToList()[0];
            }

            return single;


        }
        
        
        public static bool Exists(Expression<Func<gm_materialy_ruchy, bool>> expression,string connectionString, string providerName) {
           
            return All(connectionString,providerName).Any(expression);
        }        
        public static bool Exists(Expression<Func<gm_materialy_ruchy, bool>> expression) {
           
            return All().Any(expression);
        }        

        public static IList<gm_materialy_ruchy> Find(Expression<Func<gm_materialy_ruchy, bool>> expression) {
            
            var repo = GetRepo();
            return repo.Find(expression).ToList();
        }
        
        public static IList<gm_materialy_ruchy> Find(Expression<Func<gm_materialy_ruchy, bool>> expression,string connectionString, string providerName) {

            var repo = GetRepo(connectionString,providerName);
            return repo.Find(expression).ToList();

        }
        public static IQueryable<gm_materialy_ruchy> All(string connectionString, string providerName) {
            return GetRepo(connectionString,providerName).GetAll();
        }
        public static IQueryable<gm_materialy_ruchy> All() {
            return GetRepo().GetAll();
        }
        
        public static PagedList<gm_materialy_ruchy> GetPaged(string sortBy, int pageIndex, int pageSize,string connectionString, string providerName) {
            return GetRepo(connectionString,providerName).GetPaged(sortBy, pageIndex, pageSize);
        }
      
        public static PagedList<gm_materialy_ruchy> GetPaged(string sortBy, int pageIndex, int pageSize) {
            return GetRepo().GetPaged(sortBy, pageIndex, pageSize);
        }

        public static PagedList<gm_materialy_ruchy> GetPaged(int pageIndex, int pageSize,string connectionString, string providerName) {
            return GetRepo(connectionString,providerName).GetPaged(pageIndex, pageSize);
            
        }


        public static PagedList<gm_materialy_ruchy> GetPaged(int pageIndex, int pageSize) {
            return GetRepo().GetPaged(pageIndex, pageSize);
            
        }

        public string KeyName()
        {
            return "id";
        }

        public object KeyValue()
        {
            return this.id;
        }
        
        public void SetKeyValue(object value) {
            if (value != null && value!=DBNull.Value) {
                var settable = value.ChangeTypeTo<int>();
                this.GetType().GetProperty(this.KeyName()).SetValue(this, settable, null);
            }
        }
        
        public override string ToString(){
                            return this.nr_faktury.ToString();
                    }

        public override bool Equals(object obj){
            if(obj.GetType()==typeof(gm_materialy_ruchy)){
                gm_materialy_ruchy compare=(gm_materialy_ruchy)obj;
                return compare.KeyValue()==this.KeyValue();
            }else{
                return base.Equals(obj);
            }
        }

        
        public override int GetHashCode() {
            return this.id;
        }
        
        public string DescriptorValue()
        {
                            return this.nr_faktury.ToString();
                    }

        public string DescriptorColumn() {
            return "nr_faktury";
        }
        public static string GetKeyColumn()
        {
            return "id";
        }        
        public static string GetDescriptorColumn()
        {
            return "nr_faktury";
        }
        
        #region ' Foreign Keys '
        #endregion
        

        int _id;
        public int id
        {
            get { return _id; }
            set
            {
                if(_id!=value){
                    _id=value;
                    var col=tbl.Columns.SingleOrDefault(x=>x.Name=="id");
                    if(col!=null){
                        if(!_dirtyColumns.Any(x=>x.Name==col.Name) && _isLoaded){
                            _dirtyColumns.Add(col);
                        }
                    }
                    OnChanged();
                }
            }
        }

        int _material_id;
        public int material_id
        {
            get { return _material_id; }
            set
            {
                if(_material_id!=value){
                    _material_id=value;
                    var col=tbl.Columns.SingleOrDefault(x=>x.Name=="material_id");
                    if(col!=null){
                        if(!_dirtyColumns.Any(x=>x.Name==col.Name) && _isLoaded){
                            _dirtyColumns.Add(col);
                        }
                    }
                    OnChanged();
                }
            }
        }

        int _odbiorca_id;
        public int odbiorca_id
        {
            get { return _odbiorca_id; }
            set
            {
                if(_odbiorca_id!=value){
                    _odbiorca_id=value;
                    var col=tbl.Columns.SingleOrDefault(x=>x.Name=="odbiorca_id");
                    if(col!=null){
                        if(!_dirtyColumns.Any(x=>x.Name==col.Name) && _isLoaded){
                            _dirtyColumns.Add(col);
                        }
                    }
                    OnChanged();
                }
            }
        }

        int _wydajacy_id;
        public int wydajacy_id
        {
            get { return _wydajacy_id; }
            set
            {
                if(_wydajacy_id!=value){
                    _wydajacy_id=value;
                    var col=tbl.Columns.SingleOrDefault(x=>x.Name=="wydajacy_id");
                    if(col!=null){
                        if(!_dirtyColumns.Any(x=>x.Name==col.Name) && _isLoaded){
                            _dirtyColumns.Add(col);
                        }
                    }
                    OnChanged();
                }
            }
        }

        int _ilosc;
        public int ilosc
        {
            get { return _ilosc; }
            set
            {
                if(_ilosc!=value){
                    _ilosc=value;
                    var col=tbl.Columns.SingleOrDefault(x=>x.Name=="ilosc");
                    if(col!=null){
                        if(!_dirtyColumns.Any(x=>x.Name==col.Name) && _isLoaded){
                            _dirtyColumns.Add(col);
                        }
                    }
                    OnChanged();
                }
            }
        }

        DateTime _data;
        public DateTime data
        {
            get { return _data; }
            set
            {
                if(_data!=value){
                    _data=value;
                    var col=tbl.Columns.SingleOrDefault(x=>x.Name=="data");
                    if(col!=null){
                        if(!_dirtyColumns.Any(x=>x.Name==col.Name) && _isLoaded){
                            _dirtyColumns.Add(col);
                        }
                    }
                    OnChanged();
                }
            }
        }

        string _nr_faktury;
        public string nr_faktury
        {
            get { return _nr_faktury; }
            set
            {
                if(_nr_faktury!=value){
                    _nr_faktury=value;
                    var col=tbl.Columns.SingleOrDefault(x=>x.Name=="nr_faktury");
                    if(col!=null){
                        if(!_dirtyColumns.Any(x=>x.Name==col.Name) && _isLoaded){
                            _dirtyColumns.Add(col);
                        }
                    }
                    OnChanged();
                }
            }
        }

        int _rodzaj_ruchu;
        public int rodzaj_ruchu
        {
            get { return _rodzaj_ruchu; }
            set
            {
                if(_rodzaj_ruchu!=value){
                    _rodzaj_ruchu=value;
                    var col=tbl.Columns.SingleOrDefault(x=>x.Name=="rodzaj_ruchu");
                    if(col!=null){
                        if(!_dirtyColumns.Any(x=>x.Name==col.Name) && _isLoaded){
                            _dirtyColumns.Add(col);
                        }
                    }
                    OnChanged();
                }
            }
        }



        public DbCommand GetUpdateCommand() {
            if(TestMode)
                return _db.DataProvider.CreateCommand();
            else
                return this.ToUpdateQuery(_db.Provider).GetCommand().ToDbCommand();
            
        }
        public DbCommand GetInsertCommand() {
 
            if(TestMode)
                return _db.DataProvider.CreateCommand();
            else
                return this.ToInsertQuery(_db.Provider).GetCommand().ToDbCommand();
        }
        
        public DbCommand GetDeleteCommand() {
            if(TestMode)
                return _db.DataProvider.CreateCommand();
            else
                return this.ToDeleteQuery(_db.Provider).GetCommand().ToDbCommand();
        }
       
        
        public void Update(){
            Update(_db.DataProvider);
        }
        
        public void Update(IDataProvider provider){
        
            
            if(this._dirtyColumns.Count>0){
                _repo.Update(this,provider);
                _dirtyColumns.Clear();    
            }
            OnSaved();
       }
 
        public void Add(){
            Add(_db.DataProvider);
        }
        
        
       
        public void Add(IDataProvider provider){

            
            var key=KeyValue();
            if(key==null){
                var newKey=_repo.Add(this,provider);
                this.SetKeyValue(newKey);
            }else{
                _repo.Add(this,provider);
            }
            SetIsNew(false);
            OnSaved();
        }
        
                
        
        public void Save() {
            Save(_db.DataProvider);
        }      
        public void Save(IDataProvider provider) {
            
           
            if (_isNew) {
                Add(provider);
                
            } else {
                Update(provider);
            }
            
        }

        

        public void Delete(IDataProvider provider) {
                   
                 
            _repo.Delete(KeyValue());
            
                    }


        public void Delete() {
            Delete(_db.DataProvider);
        }


        public static void Delete(Expression<Func<gm_materialy_ruchy, bool>> expression) {
            var repo = GetRepo();
            
       
            
            repo.DeleteMany(expression);
            
        }

        

        public void Load(IDataReader rdr) {
            Load(rdr, true);
        }
        public void Load(IDataReader rdr, bool closeReader) {
            if (rdr.Read()) {

                try {
                    rdr.Load(this);
                    SetIsNew(false);
                    SetIsLoaded(true);
                } catch {
                    SetIsLoaded(false);
                    throw;
                }
            }else{
                SetIsLoaded(false);
            }

            if (closeReader)
                rdr.Dispose();
        }
        

    } 
    
    
    /// <summary>
    /// A class which represents the gm_naprawy table in the evolution Database.
    /// </summary>
    public partial class gm_naprawy: IActiveRecord
    {
    
        #region Built-in testing
        static TestRepository<gm_naprawy> _testRepo;
        

        
        static void SetTestRepo(){
            _testRepo = _testRepo ?? new TestRepository<gm_naprawy>(new Amortyzacje.Model.evolutionDB());
        }
        public static void ResetTestRepo(){
            _testRepo = null;
            SetTestRepo();
        }
        public static void Setup(List<gm_naprawy> testlist){
            SetTestRepo();
            foreach (var item in testlist)
            {
                _testRepo._items.Add(item);
            }
        }
        public static void Setup(gm_naprawy item) {
            SetTestRepo();
            _testRepo._items.Add(item);
        }
        public static void Setup(int testItems) {
            SetTestRepo();
            for(int i=0;i<testItems;i++){
                gm_naprawy item=new gm_naprawy();
                _testRepo._items.Add(item);
            }
        }
        
        public bool TestMode = false;


        #endregion

        IRepository<gm_naprawy> _repo;
        ITable tbl;
        bool _isNew;
        public bool IsNew(){
            return _isNew;
        }
        
        public void SetIsLoaded(bool isLoaded){
            _isLoaded=isLoaded;
            if(isLoaded)
                OnLoaded();
        }
        
        public void SetIsNew(bool isNew){
            _isNew=isNew;
        }
        bool _isLoaded;
        public bool IsLoaded(){
            return _isLoaded;
        }
                
        List<IColumn> _dirtyColumns;
        public bool IsDirty(){
            return _dirtyColumns.Count>0;
        }
        
        public List<IColumn> GetDirtyColumns (){
            return _dirtyColumns;
        }

        Amortyzacje.Model.evolutionDB _db;
        public gm_naprawy(string connectionString, string providerName) {

            _db=new Amortyzacje.Model.evolutionDB(connectionString, providerName);
            Init();            
         }
        void Init(){
            TestMode=this._db.DataProvider.ConnectionString.Equals("test", StringComparison.InvariantCultureIgnoreCase);
            _dirtyColumns=new List<IColumn>();
            if(TestMode){
                gm_naprawy.SetTestRepo();
                _repo=_testRepo;
            }else{
                _repo = new SubSonicRepository<gm_naprawy>(_db);
            }
            tbl=_repo.GetTable();
            SetIsNew(true);
            OnCreated();       

        }
        
        public gm_naprawy(){
             _db=new Amortyzacje.Model.evolutionDB();
            Init();            
        }
        
       
        partial void OnCreated();
            
        partial void OnLoaded();
        
        partial void OnSaved();
        
        partial void OnChanged();
        
        public IList<IColumn> Columns{
            get{
                return tbl.Columns;
            }
        }

        public gm_naprawy(Expression<Func<gm_naprawy, bool>> expression):this() {

            SetIsLoaded(_repo.Load(this,expression));
        }
        
       
        
        internal static IRepository<gm_naprawy> GetRepo(string connectionString, string providerName){
            Amortyzacje.Model.evolutionDB db;
            if(String.IsNullOrEmpty(connectionString)){
                db=new Amortyzacje.Model.evolutionDB();
            }else{
                db=new Amortyzacje.Model.evolutionDB(connectionString, providerName);
            }
            IRepository<gm_naprawy> _repo;
            
            if(db.TestMode){
                gm_naprawy.SetTestRepo();
                _repo=_testRepo;
            }else{
                _repo = new SubSonicRepository<gm_naprawy>(db);
            }
            return _repo;        
        }       
        
        internal static IRepository<gm_naprawy> GetRepo(){
            return GetRepo("","");
        }
        
        public static gm_naprawy SingleOrDefault(Expression<Func<gm_naprawy, bool>> expression) {

            var repo = GetRepo();
            var results=repo.Find(expression);
            gm_naprawy single=null;
            if(results.Count() > 0){
                single=results.ToList()[0];
                single.OnLoaded();
                single.SetIsLoaded(true);
                single.SetIsNew(false);
            }

            return single;
        }      
        
        public static gm_naprawy SingleOrDefault(Expression<Func<gm_naprawy, bool>> expression,string connectionString, string providerName) {
            var repo = GetRepo(connectionString,providerName);
            var results=repo.Find(expression);
            gm_naprawy single=null;
            if(results.Count() > 0){
                single=results.ToList()[0];
            }

            return single;


        }
        
        
        public static bool Exists(Expression<Func<gm_naprawy, bool>> expression,string connectionString, string providerName) {
           
            return All(connectionString,providerName).Any(expression);
        }        
        public static bool Exists(Expression<Func<gm_naprawy, bool>> expression) {
           
            return All().Any(expression);
        }        

        public static IList<gm_naprawy> Find(Expression<Func<gm_naprawy, bool>> expression) {
            
            var repo = GetRepo();
            return repo.Find(expression).ToList();
        }
        
        public static IList<gm_naprawy> Find(Expression<Func<gm_naprawy, bool>> expression,string connectionString, string providerName) {

            var repo = GetRepo(connectionString,providerName);
            return repo.Find(expression).ToList();

        }
        public static IQueryable<gm_naprawy> All(string connectionString, string providerName) {
            return GetRepo(connectionString,providerName).GetAll();
        }
        public static IQueryable<gm_naprawy> All() {
            return GetRepo().GetAll();
        }
        
        public static PagedList<gm_naprawy> GetPaged(string sortBy, int pageIndex, int pageSize,string connectionString, string providerName) {
            return GetRepo(connectionString,providerName).GetPaged(sortBy, pageIndex, pageSize);
        }
      
        public static PagedList<gm_naprawy> GetPaged(string sortBy, int pageIndex, int pageSize) {
            return GetRepo().GetPaged(sortBy, pageIndex, pageSize);
        }

        public static PagedList<gm_naprawy> GetPaged(int pageIndex, int pageSize,string connectionString, string providerName) {
            return GetRepo(connectionString,providerName).GetPaged(pageIndex, pageSize);
            
        }


        public static PagedList<gm_naprawy> GetPaged(int pageIndex, int pageSize) {
            return GetRepo().GetPaged(pageIndex, pageSize);
            
        }

        public string KeyName()
        {
            return "id";
        }

        public object KeyValue()
        {
            return this.id;
        }
        
        public void SetKeyValue(object value) {
            if (value != null && value!=DBNull.Value) {
                var settable = value.ChangeTypeTo<int>();
                this.GetType().GetProperty(this.KeyName()).SetValue(this, settable, null);
            }
        }
        
        public override string ToString(){
                            return this.opis.ToString();
                    }

        public override bool Equals(object obj){
            if(obj.GetType()==typeof(gm_naprawy)){
                gm_naprawy compare=(gm_naprawy)obj;
                return compare.KeyValue()==this.KeyValue();
            }else{
                return base.Equals(obj);
            }
        }

        
        public override int GetHashCode() {
            return this.id;
        }
        
        public string DescriptorValue()
        {
                            return this.opis.ToString();
                    }

        public string DescriptorColumn() {
            return "opis";
        }
        public static string GetKeyColumn()
        {
            return "id";
        }        
        public static string GetDescriptorColumn()
        {
            return "opis";
        }
        
        #region ' Foreign Keys '
        #endregion
        

        int _id;
        public int id
        {
            get { return _id; }
            set
            {
                if(_id!=value){
                    _id=value;
                    var col=tbl.Columns.SingleOrDefault(x=>x.Name=="id");
                    if(col!=null){
                        if(!_dirtyColumns.Any(x=>x.Name==col.Name) && _isLoaded){
                            _dirtyColumns.Add(col);
                        }
                    }
                    OnChanged();
                }
            }
        }

        string _opis;
        public string opis
        {
            get { return _opis; }
            set
            {
                if(_opis!=value){
                    _opis=value;
                    var col=tbl.Columns.SingleOrDefault(x=>x.Name=="opis");
                    if(col!=null){
                        if(!_dirtyColumns.Any(x=>x.Name==col.Name) && _isLoaded){
                            _dirtyColumns.Add(col);
                        }
                    }
                    OnChanged();
                }
            }
        }

        DateTime _data_rozpoczecia;
        public DateTime data_rozpoczecia
        {
            get { return _data_rozpoczecia; }
            set
            {
                if(_data_rozpoczecia!=value){
                    _data_rozpoczecia=value;
                    var col=tbl.Columns.SingleOrDefault(x=>x.Name=="data_rozpoczecia");
                    if(col!=null){
                        if(!_dirtyColumns.Any(x=>x.Name==col.Name) && _isLoaded){
                            _dirtyColumns.Add(col);
                        }
                    }
                    OnChanged();
                }
            }
        }

        DateTime _data_zakonczenia;
        public DateTime data_zakonczenia
        {
            get { return _data_zakonczenia; }
            set
            {
                if(_data_zakonczenia!=value){
                    _data_zakonczenia=value;
                    var col=tbl.Columns.SingleOrDefault(x=>x.Name=="data_zakonczenia");
                    if(col!=null){
                        if(!_dirtyColumns.Any(x=>x.Name==col.Name) && _isLoaded){
                            _dirtyColumns.Add(col);
                        }
                    }
                    OnChanged();
                }
            }
        }

        byte _typ;
        public byte typ
        {
            get { return _typ; }
            set
            {
                if(_typ!=value){
                    _typ=value;
                    var col=tbl.Columns.SingleOrDefault(x=>x.Name=="typ");
                    if(col!=null){
                        if(!_dirtyColumns.Any(x=>x.Name==col.Name) && _isLoaded){
                            _dirtyColumns.Add(col);
                        }
                    }
                    OnChanged();
                }
            }
        }

        int _wykonawca_id;
        public int wykonawca_id
        {
            get { return _wykonawca_id; }
            set
            {
                if(_wykonawca_id!=value){
                    _wykonawca_id=value;
                    var col=tbl.Columns.SingleOrDefault(x=>x.Name=="wykonawca_id");
                    if(col!=null){
                        if(!_dirtyColumns.Any(x=>x.Name==col.Name) && _isLoaded){
                            _dirtyColumns.Add(col);
                        }
                    }
                    OnChanged();
                }
            }
        }

        int _obiekt_id;
        public int obiekt_id
        {
            get { return _obiekt_id; }
            set
            {
                if(_obiekt_id!=value){
                    _obiekt_id=value;
                    var col=tbl.Columns.SingleOrDefault(x=>x.Name=="obiekt_id");
                    if(col!=null){
                        if(!_dirtyColumns.Any(x=>x.Name==col.Name) && _isLoaded){
                            _dirtyColumns.Add(col);
                        }
                    }
                    OnChanged();
                }
            }
        }

        string _uwagi;
        public string uwagi
        {
            get { return _uwagi; }
            set
            {
                if(_uwagi!=value){
                    _uwagi=value;
                    var col=tbl.Columns.SingleOrDefault(x=>x.Name=="uwagi");
                    if(col!=null){
                        if(!_dirtyColumns.Any(x=>x.Name==col.Name) && _isLoaded){
                            _dirtyColumns.Add(col);
                        }
                    }
                    OnChanged();
                }
            }
        }



        public DbCommand GetUpdateCommand() {
            if(TestMode)
                return _db.DataProvider.CreateCommand();
            else
                return this.ToUpdateQuery(_db.Provider).GetCommand().ToDbCommand();
            
        }
        public DbCommand GetInsertCommand() {
 
            if(TestMode)
                return _db.DataProvider.CreateCommand();
            else
                return this.ToInsertQuery(_db.Provider).GetCommand().ToDbCommand();
        }
        
        public DbCommand GetDeleteCommand() {
            if(TestMode)
                return _db.DataProvider.CreateCommand();
            else
                return this.ToDeleteQuery(_db.Provider).GetCommand().ToDbCommand();
        }
       
        
        public void Update(){
            Update(_db.DataProvider);
        }
        
        public void Update(IDataProvider provider){
        
            
            if(this._dirtyColumns.Count>0){
                _repo.Update(this,provider);
                _dirtyColumns.Clear();    
            }
            OnSaved();
       }
 
        public void Add(){
            Add(_db.DataProvider);
        }
        
        
       
        public void Add(IDataProvider provider){

            
            var key=KeyValue();
            if(key==null){
                var newKey=_repo.Add(this,provider);
                this.SetKeyValue(newKey);
            }else{
                _repo.Add(this,provider);
            }
            SetIsNew(false);
            OnSaved();
        }
        
                
        
        public void Save() {
            Save(_db.DataProvider);
        }      
        public void Save(IDataProvider provider) {
            
           
            if (_isNew) {
                Add(provider);
                
            } else {
                Update(provider);
            }
            
        }

        

        public void Delete(IDataProvider provider) {
                   
                 
            _repo.Delete(KeyValue());
            
                    }


        public void Delete() {
            Delete(_db.DataProvider);
        }


        public static void Delete(Expression<Func<gm_naprawy, bool>> expression) {
            var repo = GetRepo();
            
       
            
            repo.DeleteMany(expression);
            
        }

        

        public void Load(IDataReader rdr) {
            Load(rdr, true);
        }
        public void Load(IDataReader rdr, bool closeReader) {
            if (rdr.Read()) {

                try {
                    rdr.Load(this);
                    SetIsNew(false);
                    SetIsLoaded(true);
                } catch {
                    SetIsLoaded(false);
                    throw;
                }
            }else{
                SetIsLoaded(false);
            }

            if (closeReader)
                rdr.Dispose();
        }
        

    } 
    
    
    /// <summary>
    /// A class which represents the gm_srodki_trwale table in the evolution Database.
    /// </summary>
    public partial class gm_srodki_trwale: IActiveRecord
    {
    
        #region Built-in testing
        static TestRepository<gm_srodki_trwale> _testRepo;
        

        
        static void SetTestRepo(){
            _testRepo = _testRepo ?? new TestRepository<gm_srodki_trwale>(new Amortyzacje.Model.evolutionDB());
        }
        public static void ResetTestRepo(){
            _testRepo = null;
            SetTestRepo();
        }
        public static void Setup(List<gm_srodki_trwale> testlist){
            SetTestRepo();
            foreach (var item in testlist)
            {
                _testRepo._items.Add(item);
            }
        }
        public static void Setup(gm_srodki_trwale item) {
            SetTestRepo();
            _testRepo._items.Add(item);
        }
        public static void Setup(int testItems) {
            SetTestRepo();
            for(int i=0;i<testItems;i++){
                gm_srodki_trwale item=new gm_srodki_trwale();
                _testRepo._items.Add(item);
            }
        }
        
        public bool TestMode = false;


        #endregion

        IRepository<gm_srodki_trwale> _repo;
        ITable tbl;
        bool _isNew;
        public bool IsNew(){
            return _isNew;
        }
        
        public void SetIsLoaded(bool isLoaded){
            _isLoaded=isLoaded;
            if(isLoaded)
                OnLoaded();
        }
        
        public void SetIsNew(bool isNew){
            _isNew=isNew;
        }
        bool _isLoaded;
        public bool IsLoaded(){
            return _isLoaded;
        }
                
        List<IColumn> _dirtyColumns;
        public bool IsDirty(){
            return _dirtyColumns.Count>0;
        }
        
        public List<IColumn> GetDirtyColumns (){
            return _dirtyColumns;
        }

        Amortyzacje.Model.evolutionDB _db;
        public gm_srodki_trwale(string connectionString, string providerName) {

            _db=new Amortyzacje.Model.evolutionDB(connectionString, providerName);
            Init();            
         }
        void Init(){
            TestMode=this._db.DataProvider.ConnectionString.Equals("test", StringComparison.InvariantCultureIgnoreCase);
            _dirtyColumns=new List<IColumn>();
            if(TestMode){
                gm_srodki_trwale.SetTestRepo();
                _repo=_testRepo;
            }else{
                _repo = new SubSonicRepository<gm_srodki_trwale>(_db);
            }
            tbl=_repo.GetTable();
            SetIsNew(true);
            OnCreated();       

        }
        
        public gm_srodki_trwale(){
             _db=new Amortyzacje.Model.evolutionDB();
            Init();            
        }
        
       
        partial void OnCreated();
            
        partial void OnLoaded();
        
        partial void OnSaved();
        
        partial void OnChanged();
        
        public IList<IColumn> Columns{
            get{
                return tbl.Columns;
            }
        }

        public gm_srodki_trwale(Expression<Func<gm_srodki_trwale, bool>> expression):this() {

            SetIsLoaded(_repo.Load(this,expression));
        }
        
       
        
        internal static IRepository<gm_srodki_trwale> GetRepo(string connectionString, string providerName){
            Amortyzacje.Model.evolutionDB db;
            if(String.IsNullOrEmpty(connectionString)){
                db=new Amortyzacje.Model.evolutionDB();
            }else{
                db=new Amortyzacje.Model.evolutionDB(connectionString, providerName);
            }
            IRepository<gm_srodki_trwale> _repo;
            
            if(db.TestMode){
                gm_srodki_trwale.SetTestRepo();
                _repo=_testRepo;
            }else{
                _repo = new SubSonicRepository<gm_srodki_trwale>(db);
            }
            return _repo;        
        }       
        
        internal static IRepository<gm_srodki_trwale> GetRepo(){
            return GetRepo("","");
        }
        
        public static gm_srodki_trwale SingleOrDefault(Expression<Func<gm_srodki_trwale, bool>> expression) {

            var repo = GetRepo();
            var results=repo.Find(expression);
            gm_srodki_trwale single=null;
            if(results.Count() > 0){
                single=results.ToList()[0];
                single.OnLoaded();
                single.SetIsLoaded(true);
                single.SetIsNew(false);
            }

            return single;
        }      
        
        public static gm_srodki_trwale SingleOrDefault(Expression<Func<gm_srodki_trwale, bool>> expression,string connectionString, string providerName) {
            var repo = GetRepo(connectionString,providerName);
            var results=repo.Find(expression);
            gm_srodki_trwale single=null;
            if(results.Count() > 0){
                single=results.ToList()[0];
            }

            return single;


        }
        
        
        public static bool Exists(Expression<Func<gm_srodki_trwale, bool>> expression,string connectionString, string providerName) {
           
            return All(connectionString,providerName).Any(expression);
        }        
        public static bool Exists(Expression<Func<gm_srodki_trwale, bool>> expression) {
           
            return All().Any(expression);
        }        

        public static IList<gm_srodki_trwale> Find(Expression<Func<gm_srodki_trwale, bool>> expression) {
            
            var repo = GetRepo();
            return repo.Find(expression).ToList();
        }
        
        public static IList<gm_srodki_trwale> Find(Expression<Func<gm_srodki_trwale, bool>> expression,string connectionString, string providerName) {

            var repo = GetRepo(connectionString,providerName);
            return repo.Find(expression).ToList();

        }
        public static IQueryable<gm_srodki_trwale> All(string connectionString, string providerName) {
            return GetRepo(connectionString,providerName).GetAll();
        }
        public static IQueryable<gm_srodki_trwale> All() {
            return GetRepo().GetAll();
        }
        
        public static PagedList<gm_srodki_trwale> GetPaged(string sortBy, int pageIndex, int pageSize,string connectionString, string providerName) {
            return GetRepo(connectionString,providerName).GetPaged(sortBy, pageIndex, pageSize);
        }
      
        public static PagedList<gm_srodki_trwale> GetPaged(string sortBy, int pageIndex, int pageSize) {
            return GetRepo().GetPaged(sortBy, pageIndex, pageSize);
        }

        public static PagedList<gm_srodki_trwale> GetPaged(int pageIndex, int pageSize,string connectionString, string providerName) {
            return GetRepo(connectionString,providerName).GetPaged(pageIndex, pageSize);
            
        }


        public static PagedList<gm_srodki_trwale> GetPaged(int pageIndex, int pageSize) {
            return GetRepo().GetPaged(pageIndex, pageSize);
            
        }

        public string KeyName()
        {
            return "nr_ewidencyjny";
        }

        public object KeyValue()
        {
            return this.nr_ewidencyjny;
        }
        
        public void SetKeyValue(object value) {
            if (value != null && value!=DBNull.Value) {
                var settable = value.ChangeTypeTo<int>();
                this.GetType().GetProperty(this.KeyName()).SetValue(this, settable, null);
            }
        }
        
        public override string ToString(){
                            return this.data_zakupu.ToString();
                    }

        public override bool Equals(object obj){
            if(obj.GetType()==typeof(gm_srodki_trwale)){
                gm_srodki_trwale compare=(gm_srodki_trwale)obj;
                return compare.KeyValue()==this.KeyValue();
            }else{
                return base.Equals(obj);
            }
        }

        
        public override int GetHashCode() {
            return this.nr_ewidencyjny;
        }
        
        public string DescriptorValue()
        {
                            return this.data_zakupu.ToString();
                    }

        public string DescriptorColumn() {
            return "data_zakupu";
        }
        public static string GetKeyColumn()
        {
            return "nr_ewidencyjny";
        }        
        public static string GetDescriptorColumn()
        {
            return "data_zakupu";
        }
        
        #region ' Foreign Keys '
        #endregion
        

        int _nr_ewidencyjny;
        public int nr_ewidencyjny
        {
            get { return _nr_ewidencyjny; }
            set
            {
                if(_nr_ewidencyjny!=value){
                    _nr_ewidencyjny=value;
                    var col=tbl.Columns.SingleOrDefault(x=>x.Name=="nr_ewidencyjny");
                    if(col!=null){
                        if(!_dirtyColumns.Any(x=>x.Name==col.Name) && _isLoaded){
                            _dirtyColumns.Add(col);
                        }
                    }
                    OnChanged();
                }
            }
        }

        string _data_zakupu;
        public string data_zakupu
        {
            get { return _data_zakupu; }
            set
            {
                if(_data_zakupu!=value){
                    _data_zakupu=value;
                    var col=tbl.Columns.SingleOrDefault(x=>x.Name=="data_zakupu");
                    if(col!=null){
                        if(!_dirtyColumns.Any(x=>x.Name==col.Name) && _isLoaded){
                            _dirtyColumns.Add(col);
                        }
                    }
                    OnChanged();
                }
            }
        }

        ulong? _id_faktury;
        public ulong? id_faktury
        {
            get { return _id_faktury; }
            set
            {
                if(_id_faktury!=value){
                    _id_faktury=value;
                    var col=tbl.Columns.SingleOrDefault(x=>x.Name=="id_faktury");
                    if(col!=null){
                        if(!_dirtyColumns.Any(x=>x.Name==col.Name) && _isLoaded){
                            _dirtyColumns.Add(col);
                        }
                    }
                    OnChanged();
                }
            }
        }

        string _nazwa;
        public string nazwa
        {
            get { return _nazwa; }
            set
            {
                if(_nazwa!=value){
                    _nazwa=value;
                    var col=tbl.Columns.SingleOrDefault(x=>x.Name=="nazwa");
                    if(col!=null){
                        if(!_dirtyColumns.Any(x=>x.Name==col.Name) && _isLoaded){
                            _dirtyColumns.Add(col);
                        }
                    }
                    OnChanged();
                }
            }
        }

        int? _KST_id;
        public int? KST_id
        {
            get { return _KST_id; }
            set
            {
                if(_KST_id!=value){
                    _KST_id=value;
                    var col=tbl.Columns.SingleOrDefault(x=>x.Name=="KST_id");
                    if(col!=null){
                        if(!_dirtyColumns.Any(x=>x.Name==col.Name) && _isLoaded){
                            _dirtyColumns.Add(col);
                        }
                    }
                    OnChanged();
                }
            }
        }

        string _numer_fabryczny;
        public string numer_fabryczny
        {
            get { return _numer_fabryczny; }
            set
            {
                if(_numer_fabryczny!=value){
                    _numer_fabryczny=value;
                    var col=tbl.Columns.SingleOrDefault(x=>x.Name=="numer_fabryczny");
                    if(col!=null){
                        if(!_dirtyColumns.Any(x=>x.Name==col.Name) && _isLoaded){
                            _dirtyColumns.Add(col);
                        }
                    }
                    OnChanged();
                }
            }
        }

        string _data_przyjecia;
        public string data_przyjecia
        {
            get { return _data_przyjecia; }
            set
            {
                if(_data_przyjecia!=value){
                    _data_przyjecia=value;
                    var col=tbl.Columns.SingleOrDefault(x=>x.Name=="data_przyjecia");
                    if(col!=null){
                        if(!_dirtyColumns.Any(x=>x.Name==col.Name) && _isLoaded){
                            _dirtyColumns.Add(col);
                        }
                    }
                    OnChanged();
                }
            }
        }

        double? _wartosc;
        public double? wartosc
        {
            get { return _wartosc; }
            set
            {
                if(_wartosc!=value){
                    _wartosc=value;
                    var col=tbl.Columns.SingleOrDefault(x=>x.Name=="wartosc");
                    if(col!=null){
                        if(!_dirtyColumns.Any(x=>x.Name==col.Name) && _isLoaded){
                            _dirtyColumns.Add(col);
                        }
                    }
                    OnChanged();
                }
            }
        }

        double? _umorzenie;
        public double? umorzenie
        {
            get { return _umorzenie; }
            set
            {
                if(_umorzenie!=value){
                    _umorzenie=value;
                    var col=tbl.Columns.SingleOrDefault(x=>x.Name=="umorzenie");
                    if(col!=null){
                        if(!_dirtyColumns.Any(x=>x.Name==col.Name) && _isLoaded){
                            _dirtyColumns.Add(col);
                        }
                    }
                    OnChanged();
                }
            }
        }

        string _rodzaj_amortyzacji;
        public string rodzaj_amortyzacji
        {
            get { return _rodzaj_amortyzacji; }
            set
            {
                if(_rodzaj_amortyzacji!=value){
                    _rodzaj_amortyzacji=value;
                    var col=tbl.Columns.SingleOrDefault(x=>x.Name=="rodzaj_amortyzacji");
                    if(col!=null){
                        if(!_dirtyColumns.Any(x=>x.Name==col.Name) && _isLoaded){
                            _dirtyColumns.Add(col);
                        }
                    }
                    OnChanged();
                }
            }
        }

        string _data_amortyzacji;
        public string data_amortyzacji
        {
            get { return _data_amortyzacji; }
            set
            {
                if(_data_amortyzacji!=value){
                    _data_amortyzacji=value;
                    var col=tbl.Columns.SingleOrDefault(x=>x.Name=="data_amortyzacji");
                    if(col!=null){
                        if(!_dirtyColumns.Any(x=>x.Name==col.Name) && _isLoaded){
                            _dirtyColumns.Add(col);
                        }
                    }
                    OnChanged();
                }
            }
        }

        int? _osoba_odpowiedzialna;
        public int? osoba_odpowiedzialna
        {
            get { return _osoba_odpowiedzialna; }
            set
            {
                if(_osoba_odpowiedzialna!=value){
                    _osoba_odpowiedzialna=value;
                    var col=tbl.Columns.SingleOrDefault(x=>x.Name=="osoba_odpowiedzialna");
                    if(col!=null){
                        if(!_dirtyColumns.Any(x=>x.Name==col.Name) && _isLoaded){
                            _dirtyColumns.Add(col);
                        }
                    }
                    OnChanged();
                }
            }
        }

        int? _zlikwidowany;
        public int? zlikwidowany
        {
            get { return _zlikwidowany; }
            set
            {
                if(_zlikwidowany!=value){
                    _zlikwidowany=value;
                    var col=tbl.Columns.SingleOrDefault(x=>x.Name=="zlikwidowany");
                    if(col!=null){
                        if(!_dirtyColumns.Any(x=>x.Name==col.Name) && _isLoaded){
                            _dirtyColumns.Add(col);
                        }
                    }
                    OnChanged();
                }
            }
        }

        int? _umiejscowienie;
        public int? umiejscowienie
        {
            get { return _umiejscowienie; }
            set
            {
                if(_umiejscowienie!=value){
                    _umiejscowienie=value;
                    var col=tbl.Columns.SingleOrDefault(x=>x.Name=="umiejscowienie");
                    if(col!=null){
                        if(!_dirtyColumns.Any(x=>x.Name==col.Name) && _isLoaded){
                            _dirtyColumns.Add(col);
                        }
                    }
                    OnChanged();
                }
            }
        }

        string _opis;
        public string opis
        {
            get { return _opis; }
            set
            {
                if(_opis!=value){
                    _opis=value;
                    var col=tbl.Columns.SingleOrDefault(x=>x.Name=="opis");
                    if(col!=null){
                        if(!_dirtyColumns.Any(x=>x.Name==col.Name) && _isLoaded){
                            _dirtyColumns.Add(col);
                        }
                    }
                    OnChanged();
                }
            }
        }



        public DbCommand GetUpdateCommand() {
            if(TestMode)
                return _db.DataProvider.CreateCommand();
            else
                return this.ToUpdateQuery(_db.Provider).GetCommand().ToDbCommand();
            
        }
        public DbCommand GetInsertCommand() {
 
            if(TestMode)
                return _db.DataProvider.CreateCommand();
            else
                return this.ToInsertQuery(_db.Provider).GetCommand().ToDbCommand();
        }
        
        public DbCommand GetDeleteCommand() {
            if(TestMode)
                return _db.DataProvider.CreateCommand();
            else
                return this.ToDeleteQuery(_db.Provider).GetCommand().ToDbCommand();
        }
       
        
        public void Update(){
            Update(_db.DataProvider);
        }
        
        public void Update(IDataProvider provider){
        
            
            if(this._dirtyColumns.Count>0){
                _repo.Update(this,provider);
                _dirtyColumns.Clear();    
            }
            OnSaved();
       }
 
        public void Add(){
            Add(_db.DataProvider);
        }
        
        
       
        public void Add(IDataProvider provider){

            
            var key=KeyValue();
            if(key==null){
                var newKey=_repo.Add(this,provider);
                this.SetKeyValue(newKey);
            }else{
                _repo.Add(this,provider);
            }
            SetIsNew(false);
            OnSaved();
        }
        
                
        
        public void Save() {
            Save(_db.DataProvider);
        }      
        public void Save(IDataProvider provider) {
            
           
            if (_isNew) {
                Add(provider);
                
            } else {
                Update(provider);
            }
            
        }

        

        public void Delete(IDataProvider provider) {
                   
                 
            _repo.Delete(KeyValue());
            
                    }


        public void Delete() {
            Delete(_db.DataProvider);
        }


        public static void Delete(Expression<Func<gm_srodki_trwale, bool>> expression) {
            var repo = GetRepo();
            
       
            
            repo.DeleteMany(expression);
            
        }

        

        public void Load(IDataReader rdr) {
            Load(rdr, true);
        }
        public void Load(IDataReader rdr, bool closeReader) {
            if (rdr.Read()) {

                try {
                    rdr.Load(this);
                    SetIsNew(false);
                    SetIsLoaded(true);
                } catch {
                    SetIsLoaded(false);
                    throw;
                }
            }else{
                SetIsLoaded(false);
            }

            if (closeReader)
                rdr.Dispose();
        }
        

    } 
    
    
    /// <summary>
    /// A class which represents the gm_srodki_trwale_amortyzacje table in the evolution Database.
    /// </summary>
    public partial class gm_srodki_trwale_amortyzacje: IActiveRecord
    {
    
        #region Built-in testing
        static TestRepository<gm_srodki_trwale_amortyzacje> _testRepo;
        

        
        static void SetTestRepo(){
            _testRepo = _testRepo ?? new TestRepository<gm_srodki_trwale_amortyzacje>(new Amortyzacje.Model.evolutionDB());
        }
        public static void ResetTestRepo(){
            _testRepo = null;
            SetTestRepo();
        }
        public static void Setup(List<gm_srodki_trwale_amortyzacje> testlist){
            SetTestRepo();
            foreach (var item in testlist)
            {
                _testRepo._items.Add(item);
            }
        }
        public static void Setup(gm_srodki_trwale_amortyzacje item) {
            SetTestRepo();
            _testRepo._items.Add(item);
        }
        public static void Setup(int testItems) {
            SetTestRepo();
            for(int i=0;i<testItems;i++){
                gm_srodki_trwale_amortyzacje item=new gm_srodki_trwale_amortyzacje();
                _testRepo._items.Add(item);
            }
        }
        
        public bool TestMode = false;


        #endregion

        IRepository<gm_srodki_trwale_amortyzacje> _repo;
        ITable tbl;
        bool _isNew;
        public bool IsNew(){
            return _isNew;
        }
        
        public void SetIsLoaded(bool isLoaded){
            _isLoaded=isLoaded;
            if(isLoaded)
                OnLoaded();
        }
        
        public void SetIsNew(bool isNew){
            _isNew=isNew;
        }
        bool _isLoaded;
        public bool IsLoaded(){
            return _isLoaded;
        }
                
        List<IColumn> _dirtyColumns;
        public bool IsDirty(){
            return _dirtyColumns.Count>0;
        }
        
        public List<IColumn> GetDirtyColumns (){
            return _dirtyColumns;
        }

        Amortyzacje.Model.evolutionDB _db;
        public gm_srodki_trwale_amortyzacje(string connectionString, string providerName) {

            _db=new Amortyzacje.Model.evolutionDB(connectionString, providerName);
            Init();            
         }
        void Init(){
            TestMode=this._db.DataProvider.ConnectionString.Equals("test", StringComparison.InvariantCultureIgnoreCase);
            _dirtyColumns=new List<IColumn>();
            if(TestMode){
                gm_srodki_trwale_amortyzacje.SetTestRepo();
                _repo=_testRepo;
            }else{
                _repo = new SubSonicRepository<gm_srodki_trwale_amortyzacje>(_db);
            }
            tbl=_repo.GetTable();
            SetIsNew(true);
            OnCreated();       

        }
        
        public gm_srodki_trwale_amortyzacje(){
             _db=new Amortyzacje.Model.evolutionDB();
            Init();            
        }
        
       
        partial void OnCreated();
            
        partial void OnLoaded();
        
        partial void OnSaved();
        
        partial void OnChanged();
        
        public IList<IColumn> Columns{
            get{
                return tbl.Columns;
            }
        }

        public gm_srodki_trwale_amortyzacje(Expression<Func<gm_srodki_trwale_amortyzacje, bool>> expression):this() {

            SetIsLoaded(_repo.Load(this,expression));
        }
        
       
        
        internal static IRepository<gm_srodki_trwale_amortyzacje> GetRepo(string connectionString, string providerName){
            Amortyzacje.Model.evolutionDB db;
            if(String.IsNullOrEmpty(connectionString)){
                db=new Amortyzacje.Model.evolutionDB();
            }else{
                db=new Amortyzacje.Model.evolutionDB(connectionString, providerName);
            }
            IRepository<gm_srodki_trwale_amortyzacje> _repo;
            
            if(db.TestMode){
                gm_srodki_trwale_amortyzacje.SetTestRepo();
                _repo=_testRepo;
            }else{
                _repo = new SubSonicRepository<gm_srodki_trwale_amortyzacje>(db);
            }
            return _repo;        
        }       
        
        internal static IRepository<gm_srodki_trwale_amortyzacje> GetRepo(){
            return GetRepo("","");
        }
        
        public static gm_srodki_trwale_amortyzacje SingleOrDefault(Expression<Func<gm_srodki_trwale_amortyzacje, bool>> expression) {

            var repo = GetRepo();
            var results=repo.Find(expression);
            gm_srodki_trwale_amortyzacje single=null;
            if(results.Count() > 0){
                single=results.ToList()[0];
                single.OnLoaded();
                single.SetIsLoaded(true);
                single.SetIsNew(false);
            }

            return single;
        }      
        
        public static gm_srodki_trwale_amortyzacje SingleOrDefault(Expression<Func<gm_srodki_trwale_amortyzacje, bool>> expression,string connectionString, string providerName) {
            var repo = GetRepo(connectionString,providerName);
            var results=repo.Find(expression);
            gm_srodki_trwale_amortyzacje single=null;
            if(results.Count() > 0){
                single=results.ToList()[0];
            }

            return single;


        }
        
        
        public static bool Exists(Expression<Func<gm_srodki_trwale_amortyzacje, bool>> expression,string connectionString, string providerName) {
           
            return All(connectionString,providerName).Any(expression);
        }        
        public static bool Exists(Expression<Func<gm_srodki_trwale_amortyzacje, bool>> expression) {
           
            return All().Any(expression);
        }        

        public static IList<gm_srodki_trwale_amortyzacje> Find(Expression<Func<gm_srodki_trwale_amortyzacje, bool>> expression) {
            
            var repo = GetRepo();
            return repo.Find(expression).ToList();
        }
        
        public static IList<gm_srodki_trwale_amortyzacje> Find(Expression<Func<gm_srodki_trwale_amortyzacje, bool>> expression,string connectionString, string providerName) {

            var repo = GetRepo(connectionString,providerName);
            return repo.Find(expression).ToList();

        }
        public static IQueryable<gm_srodki_trwale_amortyzacje> All(string connectionString, string providerName) {
            return GetRepo(connectionString,providerName).GetAll();
        }
        public static IQueryable<gm_srodki_trwale_amortyzacje> All() {
            return GetRepo().GetAll();
        }
        
        public static PagedList<gm_srodki_trwale_amortyzacje> GetPaged(string sortBy, int pageIndex, int pageSize,string connectionString, string providerName) {
            return GetRepo(connectionString,providerName).GetPaged(sortBy, pageIndex, pageSize);
        }
      
        public static PagedList<gm_srodki_trwale_amortyzacje> GetPaged(string sortBy, int pageIndex, int pageSize) {
            return GetRepo().GetPaged(sortBy, pageIndex, pageSize);
        }

        public static PagedList<gm_srodki_trwale_amortyzacje> GetPaged(int pageIndex, int pageSize,string connectionString, string providerName) {
            return GetRepo(connectionString,providerName).GetPaged(pageIndex, pageSize);
            
        }


        public static PagedList<gm_srodki_trwale_amortyzacje> GetPaged(int pageIndex, int pageSize) {
            return GetRepo().GetPaged(pageIndex, pageSize);
            
        }

        public string KeyName()
        {
            return "id";
        }

        public object KeyValue()
        {
            return this.id;
        }
        
        public void SetKeyValue(object value) {
            if (value != null && value!=DBNull.Value) {
                var settable = value.ChangeTypeTo<int>();
                this.GetType().GetProperty(this.KeyName()).SetValue(this, settable, null);
            }
        }
        
        public override string ToString(){
                            return this.data_amortyzacji.ToString();
                    }

        public override bool Equals(object obj){
            if(obj.GetType()==typeof(gm_srodki_trwale_amortyzacje)){
                gm_srodki_trwale_amortyzacje compare=(gm_srodki_trwale_amortyzacje)obj;
                return compare.KeyValue()==this.KeyValue();
            }else{
                return base.Equals(obj);
            }
        }

        
        public override int GetHashCode() {
            return this.id;
        }
        
        public string DescriptorValue()
        {
                            return this.data_amortyzacji.ToString();
                    }

        public string DescriptorColumn() {
            return "data_amortyzacji";
        }
        public static string GetKeyColumn()
        {
            return "id";
        }        
        public static string GetDescriptorColumn()
        {
            return "data_amortyzacji";
        }
        
        #region ' Foreign Keys '
        #endregion
        

        int _id;
        public int id
        {
            get { return _id; }
            set
            {
                if(_id!=value){
                    _id=value;
                    var col=tbl.Columns.SingleOrDefault(x=>x.Name=="id");
                    if(col!=null){
                        if(!_dirtyColumns.Any(x=>x.Name==col.Name) && _isLoaded){
                            _dirtyColumns.Add(col);
                        }
                    }
                    OnChanged();
                }
            }
        }

        int _nr_ewidencyjny;
        public int nr_ewidencyjny
        {
            get { return _nr_ewidencyjny; }
            set
            {
                if(_nr_ewidencyjny!=value){
                    _nr_ewidencyjny=value;
                    var col=tbl.Columns.SingleOrDefault(x=>x.Name=="nr_ewidencyjny");
                    if(col!=null){
                        if(!_dirtyColumns.Any(x=>x.Name==col.Name) && _isLoaded){
                            _dirtyColumns.Add(col);
                        }
                    }
                    OnChanged();
                }
            }
        }

        string _data_amortyzacji;
        public string data_amortyzacji
        {
            get { return _data_amortyzacji; }
            set
            {
                if(_data_amortyzacji!=value){
                    _data_amortyzacji=value;
                    var col=tbl.Columns.SingleOrDefault(x=>x.Name=="data_amortyzacji");
                    if(col!=null){
                        if(!_dirtyColumns.Any(x=>x.Name==col.Name) && _isLoaded){
                            _dirtyColumns.Add(col);
                        }
                    }
                    OnChanged();
                }
            }
        }

        double _kwota;
        public double kwota
        {
            get { return _kwota; }
            set
            {
                if(_kwota!=value){
                    _kwota=value;
                    var col=tbl.Columns.SingleOrDefault(x=>x.Name=="kwota");
                    if(col!=null){
                        if(!_dirtyColumns.Any(x=>x.Name==col.Name) && _isLoaded){
                            _dirtyColumns.Add(col);
                        }
                    }
                    OnChanged();
                }
            }
        }



        public DbCommand GetUpdateCommand() {
            if(TestMode)
                return _db.DataProvider.CreateCommand();
            else
                return this.ToUpdateQuery(_db.Provider).GetCommand().ToDbCommand();
            
        }
        public DbCommand GetInsertCommand() {
 
            if(TestMode)
                return _db.DataProvider.CreateCommand();
            else
                return this.ToInsertQuery(_db.Provider).GetCommand().ToDbCommand();
        }
        
        public DbCommand GetDeleteCommand() {
            if(TestMode)
                return _db.DataProvider.CreateCommand();
            else
                return this.ToDeleteQuery(_db.Provider).GetCommand().ToDbCommand();
        }
       
        
        public void Update(){
            Update(_db.DataProvider);
        }
        
        public void Update(IDataProvider provider){
        
            
            if(this._dirtyColumns.Count>0){
                _repo.Update(this,provider);
                _dirtyColumns.Clear();    
            }
            OnSaved();
       }
 
        public void Add(){
            Add(_db.DataProvider);
        }
        
        
       
        public void Add(IDataProvider provider){

            
            var key=KeyValue();
            if(key==null){
                var newKey=_repo.Add(this,provider);
                this.SetKeyValue(newKey);
            }else{
                _repo.Add(this,provider);
            }
            SetIsNew(false);
            OnSaved();
        }
        
                
        
        public void Save() {
            Save(_db.DataProvider);
        }      
        public void Save(IDataProvider provider) {
            
           
            if (_isNew) {
                Add(provider);
                
            } else {
                Update(provider);
            }
            
        }

        

        public void Delete(IDataProvider provider) {
                   
                 
            _repo.Delete(KeyValue());
            
                    }


        public void Delete() {
            Delete(_db.DataProvider);
        }


        public static void Delete(Expression<Func<gm_srodki_trwale_amortyzacje, bool>> expression) {
            var repo = GetRepo();
            
       
            
            repo.DeleteMany(expression);
            
        }

        

        public void Load(IDataReader rdr) {
            Load(rdr, true);
        }
        public void Load(IDataReader rdr, bool closeReader) {
            if (rdr.Read()) {

                try {
                    rdr.Load(this);
                    SetIsNew(false);
                    SetIsLoaded(true);
                } catch {
                    SetIsLoaded(false);
                    throw;
                }
            }else{
                SetIsLoaded(false);
            }

            if (closeReader)
                rdr.Dispose();
        }
        

    } 
    
    
    /// <summary>
    /// A class which represents the gm_srodki_trwale_ruchy table in the evolution Database.
    /// </summary>
    public partial class gm_srodki_trwale_ruchy: IActiveRecord
    {
    
        #region Built-in testing
        static TestRepository<gm_srodki_trwale_ruchy> _testRepo;
        

        
        static void SetTestRepo(){
            _testRepo = _testRepo ?? new TestRepository<gm_srodki_trwale_ruchy>(new Amortyzacje.Model.evolutionDB());
        }
        public static void ResetTestRepo(){
            _testRepo = null;
            SetTestRepo();
        }
        public static void Setup(List<gm_srodki_trwale_ruchy> testlist){
            SetTestRepo();
            foreach (var item in testlist)
            {
                _testRepo._items.Add(item);
            }
        }
        public static void Setup(gm_srodki_trwale_ruchy item) {
            SetTestRepo();
            _testRepo._items.Add(item);
        }
        public static void Setup(int testItems) {
            SetTestRepo();
            for(int i=0;i<testItems;i++){
                gm_srodki_trwale_ruchy item=new gm_srodki_trwale_ruchy();
                _testRepo._items.Add(item);
            }
        }
        
        public bool TestMode = false;


        #endregion

        IRepository<gm_srodki_trwale_ruchy> _repo;
        ITable tbl;
        bool _isNew;
        public bool IsNew(){
            return _isNew;
        }
        
        public void SetIsLoaded(bool isLoaded){
            _isLoaded=isLoaded;
            if(isLoaded)
                OnLoaded();
        }
        
        public void SetIsNew(bool isNew){
            _isNew=isNew;
        }
        bool _isLoaded;
        public bool IsLoaded(){
            return _isLoaded;
        }
                
        List<IColumn> _dirtyColumns;
        public bool IsDirty(){
            return _dirtyColumns.Count>0;
        }
        
        public List<IColumn> GetDirtyColumns (){
            return _dirtyColumns;
        }

        Amortyzacje.Model.evolutionDB _db;
        public gm_srodki_trwale_ruchy(string connectionString, string providerName) {

            _db=new Amortyzacje.Model.evolutionDB(connectionString, providerName);
            Init();            
         }
        void Init(){
            TestMode=this._db.DataProvider.ConnectionString.Equals("test", StringComparison.InvariantCultureIgnoreCase);
            _dirtyColumns=new List<IColumn>();
            if(TestMode){
                gm_srodki_trwale_ruchy.SetTestRepo();
                _repo=_testRepo;
            }else{
                _repo = new SubSonicRepository<gm_srodki_trwale_ruchy>(_db);
            }
            tbl=_repo.GetTable();
            SetIsNew(true);
            OnCreated();       

        }
        
        public gm_srodki_trwale_ruchy(){
             _db=new Amortyzacje.Model.evolutionDB();
            Init();            
        }
        
       
        partial void OnCreated();
            
        partial void OnLoaded();
        
        partial void OnSaved();
        
        partial void OnChanged();
        
        public IList<IColumn> Columns{
            get{
                return tbl.Columns;
            }
        }

        public gm_srodki_trwale_ruchy(Expression<Func<gm_srodki_trwale_ruchy, bool>> expression):this() {

            SetIsLoaded(_repo.Load(this,expression));
        }
        
       
        
        internal static IRepository<gm_srodki_trwale_ruchy> GetRepo(string connectionString, string providerName){
            Amortyzacje.Model.evolutionDB db;
            if(String.IsNullOrEmpty(connectionString)){
                db=new Amortyzacje.Model.evolutionDB();
            }else{
                db=new Amortyzacje.Model.evolutionDB(connectionString, providerName);
            }
            IRepository<gm_srodki_trwale_ruchy> _repo;
            
            if(db.TestMode){
                gm_srodki_trwale_ruchy.SetTestRepo();
                _repo=_testRepo;
            }else{
                _repo = new SubSonicRepository<gm_srodki_trwale_ruchy>(db);
            }
            return _repo;        
        }       
        
        internal static IRepository<gm_srodki_trwale_ruchy> GetRepo(){
            return GetRepo("","");
        }
        
        public static gm_srodki_trwale_ruchy SingleOrDefault(Expression<Func<gm_srodki_trwale_ruchy, bool>> expression) {

            var repo = GetRepo();
            var results=repo.Find(expression);
            gm_srodki_trwale_ruchy single=null;
            if(results.Count() > 0){
                single=results.ToList()[0];
                single.OnLoaded();
                single.SetIsLoaded(true);
                single.SetIsNew(false);
            }

            return single;
        }      
        
        public static gm_srodki_trwale_ruchy SingleOrDefault(Expression<Func<gm_srodki_trwale_ruchy, bool>> expression,string connectionString, string providerName) {
            var repo = GetRepo(connectionString,providerName);
            var results=repo.Find(expression);
            gm_srodki_trwale_ruchy single=null;
            if(results.Count() > 0){
                single=results.ToList()[0];
            }

            return single;


        }
        
        
        public static bool Exists(Expression<Func<gm_srodki_trwale_ruchy, bool>> expression,string connectionString, string providerName) {
           
            return All(connectionString,providerName).Any(expression);
        }        
        public static bool Exists(Expression<Func<gm_srodki_trwale_ruchy, bool>> expression) {
           
            return All().Any(expression);
        }        

        public static IList<gm_srodki_trwale_ruchy> Find(Expression<Func<gm_srodki_trwale_ruchy, bool>> expression) {
            
            var repo = GetRepo();
            return repo.Find(expression).ToList();
        }
        
        public static IList<gm_srodki_trwale_ruchy> Find(Expression<Func<gm_srodki_trwale_ruchy, bool>> expression,string connectionString, string providerName) {

            var repo = GetRepo(connectionString,providerName);
            return repo.Find(expression).ToList();

        }
        public static IQueryable<gm_srodki_trwale_ruchy> All(string connectionString, string providerName) {
            return GetRepo(connectionString,providerName).GetAll();
        }
        public static IQueryable<gm_srodki_trwale_ruchy> All() {
            return GetRepo().GetAll();
        }
        
        public static PagedList<gm_srodki_trwale_ruchy> GetPaged(string sortBy, int pageIndex, int pageSize,string connectionString, string providerName) {
            return GetRepo(connectionString,providerName).GetPaged(sortBy, pageIndex, pageSize);
        }
      
        public static PagedList<gm_srodki_trwale_ruchy> GetPaged(string sortBy, int pageIndex, int pageSize) {
            return GetRepo().GetPaged(sortBy, pageIndex, pageSize);
        }

        public static PagedList<gm_srodki_trwale_ruchy> GetPaged(int pageIndex, int pageSize,string connectionString, string providerName) {
            return GetRepo(connectionString,providerName).GetPaged(pageIndex, pageSize);
            
        }


        public static PagedList<gm_srodki_trwale_ruchy> GetPaged(int pageIndex, int pageSize) {
            return GetRepo().GetPaged(pageIndex, pageSize);
            
        }

        public string KeyName()
        {
            return "id";
        }

        public object KeyValue()
        {
            return this.id;
        }
        
        public void SetKeyValue(object value) {
            if (value != null && value!=DBNull.Value) {
                var settable = value.ChangeTypeTo<int>();
                this.GetType().GetProperty(this.KeyName()).SetValue(this, settable, null);
            }
        }
        
        public override string ToString(){
                            return this.data_przekazania.ToString();
                    }

        public override bool Equals(object obj){
            if(obj.GetType()==typeof(gm_srodki_trwale_ruchy)){
                gm_srodki_trwale_ruchy compare=(gm_srodki_trwale_ruchy)obj;
                return compare.KeyValue()==this.KeyValue();
            }else{
                return base.Equals(obj);
            }
        }

        
        public override int GetHashCode() {
            return this.id;
        }
        
        public string DescriptorValue()
        {
                            return this.data_przekazania.ToString();
                    }

        public string DescriptorColumn() {
            return "data_przekazania";
        }
        public static string GetKeyColumn()
        {
            return "id";
        }        
        public static string GetDescriptorColumn()
        {
            return "data_przekazania";
        }
        
        #region ' Foreign Keys '
        #endregion
        

        int _id;
        public int id
        {
            get { return _id; }
            set
            {
                if(_id!=value){
                    _id=value;
                    var col=tbl.Columns.SingleOrDefault(x=>x.Name=="id");
                    if(col!=null){
                        if(!_dirtyColumns.Any(x=>x.Name==col.Name) && _isLoaded){
                            _dirtyColumns.Add(col);
                        }
                    }
                    OnChanged();
                }
            }
        }

        string _data_przekazania;
        public string data_przekazania
        {
            get { return _data_przekazania; }
            set
            {
                if(_data_przekazania!=value){
                    _data_przekazania=value;
                    var col=tbl.Columns.SingleOrDefault(x=>x.Name=="data_przekazania");
                    if(col!=null){
                        if(!_dirtyColumns.Any(x=>x.Name==col.Name) && _isLoaded){
                            _dirtyColumns.Add(col);
                        }
                    }
                    OnChanged();
                }
            }
        }

        int? _pracownik_id;
        public int? pracownik_id
        {
            get { return _pracownik_id; }
            set
            {
                if(_pracownik_id!=value){
                    _pracownik_id=value;
                    var col=tbl.Columns.SingleOrDefault(x=>x.Name=="pracownik_id");
                    if(col!=null){
                        if(!_dirtyColumns.Any(x=>x.Name==col.Name) && _isLoaded){
                            _dirtyColumns.Add(col);
                        }
                    }
                    OnChanged();
                }
            }
        }

        int? _numer_sali;
        public int? numer_sali
        {
            get { return _numer_sali; }
            set
            {
                if(_numer_sali!=value){
                    _numer_sali=value;
                    var col=tbl.Columns.SingleOrDefault(x=>x.Name=="numer_sali");
                    if(col!=null){
                        if(!_dirtyColumns.Any(x=>x.Name==col.Name) && _isLoaded){
                            _dirtyColumns.Add(col);
                        }
                    }
                    OnChanged();
                }
            }
        }

        int _srodek_id;
        public int srodek_id
        {
            get { return _srodek_id; }
            set
            {
                if(_srodek_id!=value){
                    _srodek_id=value;
                    var col=tbl.Columns.SingleOrDefault(x=>x.Name=="srodek_id");
                    if(col!=null){
                        if(!_dirtyColumns.Any(x=>x.Name==col.Name) && _isLoaded){
                            _dirtyColumns.Add(col);
                        }
                    }
                    OnChanged();
                }
            }
        }



        public DbCommand GetUpdateCommand() {
            if(TestMode)
                return _db.DataProvider.CreateCommand();
            else
                return this.ToUpdateQuery(_db.Provider).GetCommand().ToDbCommand();
            
        }
        public DbCommand GetInsertCommand() {
 
            if(TestMode)
                return _db.DataProvider.CreateCommand();
            else
                return this.ToInsertQuery(_db.Provider).GetCommand().ToDbCommand();
        }
        
        public DbCommand GetDeleteCommand() {
            if(TestMode)
                return _db.DataProvider.CreateCommand();
            else
                return this.ToDeleteQuery(_db.Provider).GetCommand().ToDbCommand();
        }
       
        
        public void Update(){
            Update(_db.DataProvider);
        }
        
        public void Update(IDataProvider provider){
        
            
            if(this._dirtyColumns.Count>0){
                _repo.Update(this,provider);
                _dirtyColumns.Clear();    
            }
            OnSaved();
       }
 
        public void Add(){
            Add(_db.DataProvider);
        }
        
        
       
        public void Add(IDataProvider provider){

            
            var key=KeyValue();
            if(key==null){
                var newKey=_repo.Add(this,provider);
                this.SetKeyValue(newKey);
            }else{
                _repo.Add(this,provider);
            }
            SetIsNew(false);
            OnSaved();
        }
        
                
        
        public void Save() {
            Save(_db.DataProvider);
        }      
        public void Save(IDataProvider provider) {
            
           
            if (_isNew) {
                Add(provider);
                
            } else {
                Update(provider);
            }
            
        }

        

        public void Delete(IDataProvider provider) {
                   
                 
            _repo.Delete(KeyValue());
            
                    }


        public void Delete() {
            Delete(_db.DataProvider);
        }


        public static void Delete(Expression<Func<gm_srodki_trwale_ruchy, bool>> expression) {
            var repo = GetRepo();
            
       
            
            repo.DeleteMany(expression);
            
        }

        

        public void Load(IDataReader rdr) {
            Load(rdr, true);
        }
        public void Load(IDataReader rdr, bool closeReader) {
            if (rdr.Read()) {

                try {
                    rdr.Load(this);
                    SetIsNew(false);
                    SetIsLoaded(true);
                } catch {
                    SetIsLoaded(false);
                    throw;
                }
            }else{
                SetIsLoaded(false);
            }

            if (closeReader)
                rdr.Dispose();
        }
        

    } 
    
    
    /// <summary>
    /// A class which represents the konta table in the evolution Database.
    /// </summary>
    public partial class kontum: IActiveRecord
    {
    
        #region Built-in testing
        static TestRepository<kontum> _testRepo;
        

        
        static void SetTestRepo(){
            _testRepo = _testRepo ?? new TestRepository<kontum>(new Amortyzacje.Model.evolutionDB());
        }
        public static void ResetTestRepo(){
            _testRepo = null;
            SetTestRepo();
        }
        public static void Setup(List<kontum> testlist){
            SetTestRepo();
            foreach (var item in testlist)
            {
                _testRepo._items.Add(item);
            }
        }
        public static void Setup(kontum item) {
            SetTestRepo();
            _testRepo._items.Add(item);
        }
        public static void Setup(int testItems) {
            SetTestRepo();
            for(int i=0;i<testItems;i++){
                kontum item=new kontum();
                _testRepo._items.Add(item);
            }
        }
        
        public bool TestMode = false;


        #endregion

        IRepository<kontum> _repo;
        ITable tbl;
        bool _isNew;
        public bool IsNew(){
            return _isNew;
        }
        
        public void SetIsLoaded(bool isLoaded){
            _isLoaded=isLoaded;
            if(isLoaded)
                OnLoaded();
        }
        
        public void SetIsNew(bool isNew){
            _isNew=isNew;
        }
        bool _isLoaded;
        public bool IsLoaded(){
            return _isLoaded;
        }
                
        List<IColumn> _dirtyColumns;
        public bool IsDirty(){
            return _dirtyColumns.Count>0;
        }
        
        public List<IColumn> GetDirtyColumns (){
            return _dirtyColumns;
        }

        Amortyzacje.Model.evolutionDB _db;
        public kontum(string connectionString, string providerName) {

            _db=new Amortyzacje.Model.evolutionDB(connectionString, providerName);
            Init();            
         }
        void Init(){
            TestMode=this._db.DataProvider.ConnectionString.Equals("test", StringComparison.InvariantCultureIgnoreCase);
            _dirtyColumns=new List<IColumn>();
            if(TestMode){
                kontum.SetTestRepo();
                _repo=_testRepo;
            }else{
                _repo = new SubSonicRepository<kontum>(_db);
            }
            tbl=_repo.GetTable();
            SetIsNew(true);
            OnCreated();       

        }
        
        public kontum(){
             _db=new Amortyzacje.Model.evolutionDB();
            Init();            
        }
        
       
        partial void OnCreated();
            
        partial void OnLoaded();
        
        partial void OnSaved();
        
        partial void OnChanged();
        
        public IList<IColumn> Columns{
            get{
                return tbl.Columns;
            }
        }

        public kontum(Expression<Func<kontum, bool>> expression):this() {

            SetIsLoaded(_repo.Load(this,expression));
        }
        
       
        
        internal static IRepository<kontum> GetRepo(string connectionString, string providerName){
            Amortyzacje.Model.evolutionDB db;
            if(String.IsNullOrEmpty(connectionString)){
                db=new Amortyzacje.Model.evolutionDB();
            }else{
                db=new Amortyzacje.Model.evolutionDB(connectionString, providerName);
            }
            IRepository<kontum> _repo;
            
            if(db.TestMode){
                kontum.SetTestRepo();
                _repo=_testRepo;
            }else{
                _repo = new SubSonicRepository<kontum>(db);
            }
            return _repo;        
        }       
        
        internal static IRepository<kontum> GetRepo(){
            return GetRepo("","");
        }
        
        public static kontum SingleOrDefault(Expression<Func<kontum, bool>> expression) {

            var repo = GetRepo();
            var results=repo.Find(expression);
            kontum single=null;
            if(results.Count() > 0){
                single=results.ToList()[0];
                single.OnLoaded();
                single.SetIsLoaded(true);
                single.SetIsNew(false);
            }

            return single;
        }      
        
        public static kontum SingleOrDefault(Expression<Func<kontum, bool>> expression,string connectionString, string providerName) {
            var repo = GetRepo(connectionString,providerName);
            var results=repo.Find(expression);
            kontum single=null;
            if(results.Count() > 0){
                single=results.ToList()[0];
            }

            return single;


        }
        
        
        public static bool Exists(Expression<Func<kontum, bool>> expression,string connectionString, string providerName) {
           
            return All(connectionString,providerName).Any(expression);
        }        
        public static bool Exists(Expression<Func<kontum, bool>> expression) {
           
            return All().Any(expression);
        }        

        public static IList<kontum> Find(Expression<Func<kontum, bool>> expression) {
            
            var repo = GetRepo();
            return repo.Find(expression).ToList();
        }
        
        public static IList<kontum> Find(Expression<Func<kontum, bool>> expression,string connectionString, string providerName) {

            var repo = GetRepo(connectionString,providerName);
            return repo.Find(expression).ToList();

        }
        public static IQueryable<kontum> All(string connectionString, string providerName) {
            return GetRepo(connectionString,providerName).GetAll();
        }
        public static IQueryable<kontum> All() {
            return GetRepo().GetAll();
        }
        
        public static PagedList<kontum> GetPaged(string sortBy, int pageIndex, int pageSize,string connectionString, string providerName) {
            return GetRepo(connectionString,providerName).GetPaged(sortBy, pageIndex, pageSize);
        }
      
        public static PagedList<kontum> GetPaged(string sortBy, int pageIndex, int pageSize) {
            return GetRepo().GetPaged(sortBy, pageIndex, pageSize);
        }

        public static PagedList<kontum> GetPaged(int pageIndex, int pageSize,string connectionString, string providerName) {
            return GetRepo(connectionString,providerName).GetPaged(pageIndex, pageSize);
            
        }


        public static PagedList<kontum> GetPaged(int pageIndex, int pageSize) {
            return GetRepo().GetPaged(pageIndex, pageSize);
            
        }

        public string KeyName()
        {
            return "id";
        }

        public object KeyValue()
        {
            return this.id;
        }
        
        public void SetKeyValue(object value) {
            if (value != null && value!=DBNull.Value) {
                var settable = value.ChangeTypeTo<int>();
                this.GetType().GetProperty(this.KeyName()).SetValue(this, settable, null);
            }
        }
        
        public override string ToString(){
                            return this.nazwa_konta.ToString();
                    }

        public override bool Equals(object obj){
            if(obj.GetType()==typeof(kontum)){
                kontum compare=(kontum)obj;
                return compare.KeyValue()==this.KeyValue();
            }else{
                return base.Equals(obj);
            }
        }

        
        public override int GetHashCode() {
            return this.id;
        }
        
        public string DescriptorValue()
        {
                            return this.nazwa_konta.ToString();
                    }

        public string DescriptorColumn() {
            return "nazwa_konta";
        }
        public static string GetKeyColumn()
        {
            return "id";
        }        
        public static string GetDescriptorColumn()
        {
            return "nazwa_konta";
        }
        
        #region ' Foreign Keys '
        #endregion
        

        int _id;
        public int id
        {
            get { return _id; }
            set
            {
                if(_id!=value){
                    _id=value;
                    var col=tbl.Columns.SingleOrDefault(x=>x.Name=="id");
                    if(col!=null){
                        if(!_dirtyColumns.Any(x=>x.Name==col.Name) && _isLoaded){
                            _dirtyColumns.Add(col);
                        }
                    }
                    OnChanged();
                }
            }
        }

        int _numer;
        public int numer
        {
            get { return _numer; }
            set
            {
                if(_numer!=value){
                    _numer=value;
                    var col=tbl.Columns.SingleOrDefault(x=>x.Name=="numer");
                    if(col!=null){
                        if(!_dirtyColumns.Any(x=>x.Name==col.Name) && _isLoaded){
                            _dirtyColumns.Add(col);
                        }
                    }
                    OnChanged();
                }
            }
        }

        string _nazwa_konta;
        public string nazwa_konta
        {
            get { return _nazwa_konta; }
            set
            {
                if(_nazwa_konta!=value){
                    _nazwa_konta=value;
                    var col=tbl.Columns.SingleOrDefault(x=>x.Name=="nazwa_konta");
                    if(col!=null){
                        if(!_dirtyColumns.Any(x=>x.Name==col.Name) && _isLoaded){
                            _dirtyColumns.Add(col);
                        }
                    }
                    OnChanged();
                }
            }
        }



        public DbCommand GetUpdateCommand() {
            if(TestMode)
                return _db.DataProvider.CreateCommand();
            else
                return this.ToUpdateQuery(_db.Provider).GetCommand().ToDbCommand();
            
        }
        public DbCommand GetInsertCommand() {
 
            if(TestMode)
                return _db.DataProvider.CreateCommand();
            else
                return this.ToInsertQuery(_db.Provider).GetCommand().ToDbCommand();
        }
        
        public DbCommand GetDeleteCommand() {
            if(TestMode)
                return _db.DataProvider.CreateCommand();
            else
                return this.ToDeleteQuery(_db.Provider).GetCommand().ToDbCommand();
        }
       
        
        public void Update(){
            Update(_db.DataProvider);
        }
        
        public void Update(IDataProvider provider){
        
            
            if(this._dirtyColumns.Count>0){
                _repo.Update(this,provider);
                _dirtyColumns.Clear();    
            }
            OnSaved();
       }
 
        public void Add(){
            Add(_db.DataProvider);
        }
        
        
       
        public void Add(IDataProvider provider){

            
            var key=KeyValue();
            if(key==null){
                var newKey=_repo.Add(this,provider);
                this.SetKeyValue(newKey);
            }else{
                _repo.Add(this,provider);
            }
            SetIsNew(false);
            OnSaved();
        }
        
                
        
        public void Save() {
            Save(_db.DataProvider);
        }      
        public void Save(IDataProvider provider) {
            
           
            if (_isNew) {
                Add(provider);
                
            } else {
                Update(provider);
            }
            
        }

        

        public void Delete(IDataProvider provider) {
                   
                 
            _repo.Delete(KeyValue());
            
                    }


        public void Delete() {
            Delete(_db.DataProvider);
        }


        public static void Delete(Expression<Func<kontum, bool>> expression) {
            var repo = GetRepo();
            
       
            
            repo.DeleteMany(expression);
            
        }

        

        public void Load(IDataReader rdr) {
            Load(rdr, true);
        }
        public void Load(IDataReader rdr, bool closeReader) {
            if (rdr.Read()) {

                try {
                    rdr.Load(this);
                    SetIsNew(false);
                    SetIsLoaded(true);
                } catch {
                    SetIsLoaded(false);
                    throw;
                }
            }else{
                SetIsLoaded(false);
            }

            if (closeReader)
                rdr.Dispose();
        }
        

    } 
    
    
    /// <summary>
    /// A class which represents the ksiega table in the evolution Database.
    /// </summary>
    public partial class ksiega: IActiveRecord
    {
    
        #region Built-in testing
        static TestRepository<ksiega> _testRepo;
        

        
        static void SetTestRepo(){
            _testRepo = _testRepo ?? new TestRepository<ksiega>(new Amortyzacje.Model.evolutionDB());
        }
        public static void ResetTestRepo(){
            _testRepo = null;
            SetTestRepo();
        }
        public static void Setup(List<ksiega> testlist){
            SetTestRepo();
            foreach (var item in testlist)
            {
                _testRepo._items.Add(item);
            }
        }
        public static void Setup(ksiega item) {
            SetTestRepo();
            _testRepo._items.Add(item);
        }
        public static void Setup(int testItems) {
            SetTestRepo();
            for(int i=0;i<testItems;i++){
                ksiega item=new ksiega();
                _testRepo._items.Add(item);
            }
        }
        
        public bool TestMode = false;


        #endregion

        IRepository<ksiega> _repo;
        ITable tbl;
        bool _isNew;
        public bool IsNew(){
            return _isNew;
        }
        
        public void SetIsLoaded(bool isLoaded){
            _isLoaded=isLoaded;
            if(isLoaded)
                OnLoaded();
        }
        
        public void SetIsNew(bool isNew){
            _isNew=isNew;
        }
        bool _isLoaded;
        public bool IsLoaded(){
            return _isLoaded;
        }
                
        List<IColumn> _dirtyColumns;
        public bool IsDirty(){
            return _dirtyColumns.Count>0;
        }
        
        public List<IColumn> GetDirtyColumns (){
            return _dirtyColumns;
        }

        Amortyzacje.Model.evolutionDB _db;
        public ksiega(string connectionString, string providerName) {

            _db=new Amortyzacje.Model.evolutionDB(connectionString, providerName);
            Init();            
         }
        void Init(){
            TestMode=this._db.DataProvider.ConnectionString.Equals("test", StringComparison.InvariantCultureIgnoreCase);
            _dirtyColumns=new List<IColumn>();
            if(TestMode){
                ksiega.SetTestRepo();
                _repo=_testRepo;
            }else{
                _repo = new SubSonicRepository<ksiega>(_db);
            }
            tbl=_repo.GetTable();
            SetIsNew(true);
            OnCreated();       

        }
        
        public ksiega(){
             _db=new Amortyzacje.Model.evolutionDB();
            Init();            
        }
        
       
        partial void OnCreated();
            
        partial void OnLoaded();
        
        partial void OnSaved();
        
        partial void OnChanged();
        
        public IList<IColumn> Columns{
            get{
                return tbl.Columns;
            }
        }

        public ksiega(Expression<Func<ksiega, bool>> expression):this() {

            SetIsLoaded(_repo.Load(this,expression));
        }
        
       
        
        internal static IRepository<ksiega> GetRepo(string connectionString, string providerName){
            Amortyzacje.Model.evolutionDB db;
            if(String.IsNullOrEmpty(connectionString)){
                db=new Amortyzacje.Model.evolutionDB();
            }else{
                db=new Amortyzacje.Model.evolutionDB(connectionString, providerName);
            }
            IRepository<ksiega> _repo;
            
            if(db.TestMode){
                ksiega.SetTestRepo();
                _repo=_testRepo;
            }else{
                _repo = new SubSonicRepository<ksiega>(db);
            }
            return _repo;        
        }       
        
        internal static IRepository<ksiega> GetRepo(){
            return GetRepo("","");
        }
        
        public static ksiega SingleOrDefault(Expression<Func<ksiega, bool>> expression) {

            var repo = GetRepo();
            var results=repo.Find(expression);
            ksiega single=null;
            if(results.Count() > 0){
                single=results.ToList()[0];
                single.OnLoaded();
                single.SetIsLoaded(true);
                single.SetIsNew(false);
            }

            return single;
        }      
        
        public static ksiega SingleOrDefault(Expression<Func<ksiega, bool>> expression,string connectionString, string providerName) {
            var repo = GetRepo(connectionString,providerName);
            var results=repo.Find(expression);
            ksiega single=null;
            if(results.Count() > 0){
                single=results.ToList()[0];
            }

            return single;


        }
        
        
        public static bool Exists(Expression<Func<ksiega, bool>> expression,string connectionString, string providerName) {
           
            return All(connectionString,providerName).Any(expression);
        }        
        public static bool Exists(Expression<Func<ksiega, bool>> expression) {
           
            return All().Any(expression);
        }        

        public static IList<ksiega> Find(Expression<Func<ksiega, bool>> expression) {
            
            var repo = GetRepo();
            return repo.Find(expression).ToList();
        }
        
        public static IList<ksiega> Find(Expression<Func<ksiega, bool>> expression,string connectionString, string providerName) {

            var repo = GetRepo(connectionString,providerName);
            return repo.Find(expression).ToList();

        }
        public static IQueryable<ksiega> All(string connectionString, string providerName) {
            return GetRepo(connectionString,providerName).GetAll();
        }
        public static IQueryable<ksiega> All() {
            return GetRepo().GetAll();
        }
        
        public static PagedList<ksiega> GetPaged(string sortBy, int pageIndex, int pageSize,string connectionString, string providerName) {
            return GetRepo(connectionString,providerName).GetPaged(sortBy, pageIndex, pageSize);
        }
      
        public static PagedList<ksiega> GetPaged(string sortBy, int pageIndex, int pageSize) {
            return GetRepo().GetPaged(sortBy, pageIndex, pageSize);
        }

        public static PagedList<ksiega> GetPaged(int pageIndex, int pageSize,string connectionString, string providerName) {
            return GetRepo(connectionString,providerName).GetPaged(pageIndex, pageSize);
            
        }


        public static PagedList<ksiega> GetPaged(int pageIndex, int pageSize) {
            return GetRepo().GetPaged(pageIndex, pageSize);
            
        }

        public string KeyName()
        {
            return "id";
        }

        public object KeyValue()
        {
            return this.id;
        }
        
        public void SetKeyValue(object value) {
            if (value != null && value!=DBNull.Value) {
                var settable = value.ChangeTypeTo<ulong>();
                this.GetType().GetProperty(this.KeyName()).SetValue(this, settable, null);
            }
        }
        
        public override string ToString(){
                            return this.nazwa.ToString();
                    }

        public override bool Equals(object obj){
            if(obj.GetType()==typeof(ksiega)){
                ksiega compare=(ksiega)obj;
                return compare.KeyValue()==this.KeyValue();
            }else{
                return base.Equals(obj);
            }
        }

        public string DescriptorValue()
        {
                            return this.nazwa.ToString();
                    }

        public string DescriptorColumn() {
            return "nazwa";
        }
        public static string GetKeyColumn()
        {
            return "id";
        }        
        public static string GetDescriptorColumn()
        {
            return "nazwa";
        }
        
        #region ' Foreign Keys '
        #endregion
        

        ulong _id;
        public ulong id
        {
            get { return _id; }
            set
            {
                if(_id!=value){
                    _id=value;
                    var col=tbl.Columns.SingleOrDefault(x=>x.Name=="id");
                    if(col!=null){
                        if(!_dirtyColumns.Any(x=>x.Name==col.Name) && _isLoaded){
                            _dirtyColumns.Add(col);
                        }
                    }
                    OnChanged();
                }
            }
        }

        decimal _kwota;
        public decimal kwota
        {
            get { return _kwota; }
            set
            {
                if(_kwota!=value){
                    _kwota=value;
                    var col=tbl.Columns.SingleOrDefault(x=>x.Name=="kwota");
                    if(col!=null){
                        if(!_dirtyColumns.Any(x=>x.Name==col.Name) && _isLoaded){
                            _dirtyColumns.Add(col);
                        }
                    }
                    OnChanged();
                }
            }
        }

        DateTime _data;
        public DateTime data
        {
            get { return _data; }
            set
            {
                if(_data!=value){
                    _data=value;
                    var col=tbl.Columns.SingleOrDefault(x=>x.Name=="data");
                    if(col!=null){
                        if(!_dirtyColumns.Any(x=>x.Name==col.Name) && _isLoaded){
                            _dirtyColumns.Add(col);
                        }
                    }
                    OnChanged();
                }
            }
        }

        int _id_konta;
        public int id_konta
        {
            get { return _id_konta; }
            set
            {
                if(_id_konta!=value){
                    _id_konta=value;
                    var col=tbl.Columns.SingleOrDefault(x=>x.Name=="id_konta");
                    if(col!=null){
                        if(!_dirtyColumns.Any(x=>x.Name==col.Name) && _isLoaded){
                            _dirtyColumns.Add(col);
                        }
                    }
                    OnChanged();
                }
            }
        }

        short _rodzaj;
        public short rodzaj
        {
            get { return _rodzaj; }
            set
            {
                if(_rodzaj!=value){
                    _rodzaj=value;
                    var col=tbl.Columns.SingleOrDefault(x=>x.Name=="rodzaj");
                    if(col!=null){
                        if(!_dirtyColumns.Any(x=>x.Name==col.Name) && _isLoaded){
                            _dirtyColumns.Add(col);
                        }
                    }
                    OnChanged();
                }
            }
        }

        ulong? _id_odwolania;
        public ulong? id_odwolania
        {
            get { return _id_odwolania; }
            set
            {
                if(_id_odwolania!=value){
                    _id_odwolania=value;
                    var col=tbl.Columns.SingleOrDefault(x=>x.Name=="id_odwolania");
                    if(col!=null){
                        if(!_dirtyColumns.Any(x=>x.Name==col.Name) && _isLoaded){
                            _dirtyColumns.Add(col);
                        }
                    }
                    OnChanged();
                }
            }
        }

        string _nazwa;
        public string nazwa
        {
            get { return _nazwa; }
            set
            {
                if(_nazwa!=value){
                    _nazwa=value;
                    var col=tbl.Columns.SingleOrDefault(x=>x.Name=="nazwa");
                    if(col!=null){
                        if(!_dirtyColumns.Any(x=>x.Name==col.Name) && _isLoaded){
                            _dirtyColumns.Add(col);
                        }
                    }
                    OnChanged();
                }
            }
        }



        public DbCommand GetUpdateCommand() {
            if(TestMode)
                return _db.DataProvider.CreateCommand();
            else
                return this.ToUpdateQuery(_db.Provider).GetCommand().ToDbCommand();
            
        }
        public DbCommand GetInsertCommand() {
 
            if(TestMode)
                return _db.DataProvider.CreateCommand();
            else
                return this.ToInsertQuery(_db.Provider).GetCommand().ToDbCommand();
        }
        
        public DbCommand GetDeleteCommand() {
            if(TestMode)
                return _db.DataProvider.CreateCommand();
            else
                return this.ToDeleteQuery(_db.Provider).GetCommand().ToDbCommand();
        }
       
        
        public void Update(){
            Update(_db.DataProvider);
        }
        
        public void Update(IDataProvider provider){
        
            
            if(this._dirtyColumns.Count>0){
                _repo.Update(this,provider);
                _dirtyColumns.Clear();    
            }
            OnSaved();
       }
 
        public void Add(){
            Add(_db.DataProvider);
        }
        
        
       
        public void Add(IDataProvider provider){

            
            var key=KeyValue();
            if(key==null){
                var newKey=_repo.Add(this,provider);
                this.SetKeyValue(newKey);
            }else{
                _repo.Add(this,provider);
            }
            SetIsNew(false);
            OnSaved();
        }
        
                
        
        public void Save() {
            Save(_db.DataProvider);
        }      
        public void Save(IDataProvider provider) {
            
           
            if (_isNew) {
                Add(provider);
                
            } else {
                Update(provider);
            }
            
        }

        

        public void Delete(IDataProvider provider) {
                   
                 
            _repo.Delete(KeyValue());
            
                    }


        public void Delete() {
            Delete(_db.DataProvider);
        }


        public static void Delete(Expression<Func<ksiega, bool>> expression) {
            var repo = GetRepo();
            
       
            
            repo.DeleteMany(expression);
            
        }

        

        public void Load(IDataReader rdr) {
            Load(rdr, true);
        }
        public void Load(IDataReader rdr, bool closeReader) {
            if (rdr.Read()) {

                try {
                    rdr.Load(this);
                    SetIsNew(false);
                    SetIsLoaded(true);
                } catch {
                    SetIsLoaded(false);
                    throw;
                }
            }else{
                SetIsLoaded(false);
            }

            if (closeReader)
                rdr.Dispose();
        }
        

    } 
    
    
    /// <summary>
    /// A class which represents the marketing_projekty table in the evolution Database.
    /// </summary>
    public partial class marketing_projekty: IActiveRecord
    {
    
        #region Built-in testing
        static TestRepository<marketing_projekty> _testRepo;
        

        
        static void SetTestRepo(){
            _testRepo = _testRepo ?? new TestRepository<marketing_projekty>(new Amortyzacje.Model.evolutionDB());
        }
        public static void ResetTestRepo(){
            _testRepo = null;
            SetTestRepo();
        }
        public static void Setup(List<marketing_projekty> testlist){
            SetTestRepo();
            foreach (var item in testlist)
            {
                _testRepo._items.Add(item);
            }
        }
        public static void Setup(marketing_projekty item) {
            SetTestRepo();
            _testRepo._items.Add(item);
        }
        public static void Setup(int testItems) {
            SetTestRepo();
            for(int i=0;i<testItems;i++){
                marketing_projekty item=new marketing_projekty();
                _testRepo._items.Add(item);
            }
        }
        
        public bool TestMode = false;


        #endregion

        IRepository<marketing_projekty> _repo;
        ITable tbl;
        bool _isNew;
        public bool IsNew(){
            return _isNew;
        }
        
        public void SetIsLoaded(bool isLoaded){
            _isLoaded=isLoaded;
            if(isLoaded)
                OnLoaded();
        }
        
        public void SetIsNew(bool isNew){
            _isNew=isNew;
        }
        bool _isLoaded;
        public bool IsLoaded(){
            return _isLoaded;
        }
                
        List<IColumn> _dirtyColumns;
        public bool IsDirty(){
            return _dirtyColumns.Count>0;
        }
        
        public List<IColumn> GetDirtyColumns (){
            return _dirtyColumns;
        }

        Amortyzacje.Model.evolutionDB _db;
        public marketing_projekty(string connectionString, string providerName) {

            _db=new Amortyzacje.Model.evolutionDB(connectionString, providerName);
            Init();            
         }
        void Init(){
            TestMode=this._db.DataProvider.ConnectionString.Equals("test", StringComparison.InvariantCultureIgnoreCase);
            _dirtyColumns=new List<IColumn>();
            if(TestMode){
                marketing_projekty.SetTestRepo();
                _repo=_testRepo;
            }else{
                _repo = new SubSonicRepository<marketing_projekty>(_db);
            }
            tbl=_repo.GetTable();
            SetIsNew(true);
            OnCreated();       

        }
        
        public marketing_projekty(){
             _db=new Amortyzacje.Model.evolutionDB();
            Init();            
        }
        
       
        partial void OnCreated();
            
        partial void OnLoaded();
        
        partial void OnSaved();
        
        partial void OnChanged();
        
        public IList<IColumn> Columns{
            get{
                return tbl.Columns;
            }
        }

        public marketing_projekty(Expression<Func<marketing_projekty, bool>> expression):this() {

            SetIsLoaded(_repo.Load(this,expression));
        }
        
       
        
        internal static IRepository<marketing_projekty> GetRepo(string connectionString, string providerName){
            Amortyzacje.Model.evolutionDB db;
            if(String.IsNullOrEmpty(connectionString)){
                db=new Amortyzacje.Model.evolutionDB();
            }else{
                db=new Amortyzacje.Model.evolutionDB(connectionString, providerName);
            }
            IRepository<marketing_projekty> _repo;
            
            if(db.TestMode){
                marketing_projekty.SetTestRepo();
                _repo=_testRepo;
            }else{
                _repo = new SubSonicRepository<marketing_projekty>(db);
            }
            return _repo;        
        }       
        
        internal static IRepository<marketing_projekty> GetRepo(){
            return GetRepo("","");
        }
        
        public static marketing_projekty SingleOrDefault(Expression<Func<marketing_projekty, bool>> expression) {

            var repo = GetRepo();
            var results=repo.Find(expression);
            marketing_projekty single=null;
            if(results.Count() > 0){
                single=results.ToList()[0];
                single.OnLoaded();
                single.SetIsLoaded(true);
                single.SetIsNew(false);
            }

            return single;
        }      
        
        public static marketing_projekty SingleOrDefault(Expression<Func<marketing_projekty, bool>> expression,string connectionString, string providerName) {
            var repo = GetRepo(connectionString,providerName);
            var results=repo.Find(expression);
            marketing_projekty single=null;
            if(results.Count() > 0){
                single=results.ToList()[0];
            }

            return single;


        }
        
        
        public static bool Exists(Expression<Func<marketing_projekty, bool>> expression,string connectionString, string providerName) {
           
            return All(connectionString,providerName).Any(expression);
        }        
        public static bool Exists(Expression<Func<marketing_projekty, bool>> expression) {
           
            return All().Any(expression);
        }        

        public static IList<marketing_projekty> Find(Expression<Func<marketing_projekty, bool>> expression) {
            
            var repo = GetRepo();
            return repo.Find(expression).ToList();
        }
        
        public static IList<marketing_projekty> Find(Expression<Func<marketing_projekty, bool>> expression,string connectionString, string providerName) {

            var repo = GetRepo(connectionString,providerName);
            return repo.Find(expression).ToList();

        }
        public static IQueryable<marketing_projekty> All(string connectionString, string providerName) {
            return GetRepo(connectionString,providerName).GetAll();
        }
        public static IQueryable<marketing_projekty> All() {
            return GetRepo().GetAll();
        }
        
        public static PagedList<marketing_projekty> GetPaged(string sortBy, int pageIndex, int pageSize,string connectionString, string providerName) {
            return GetRepo(connectionString,providerName).GetPaged(sortBy, pageIndex, pageSize);
        }
      
        public static PagedList<marketing_projekty> GetPaged(string sortBy, int pageIndex, int pageSize) {
            return GetRepo().GetPaged(sortBy, pageIndex, pageSize);
        }

        public static PagedList<marketing_projekty> GetPaged(int pageIndex, int pageSize,string connectionString, string providerName) {
            return GetRepo(connectionString,providerName).GetPaged(pageIndex, pageSize);
            
        }


        public static PagedList<marketing_projekty> GetPaged(int pageIndex, int pageSize) {
            return GetRepo().GetPaged(pageIndex, pageSize);
            
        }

        public string KeyName()
        {
            return "idprojekt";
        }

        public object KeyValue()
        {
            return this.idprojekt;
        }
        
        public void SetKeyValue(object value) {
            if (value != null && value!=DBNull.Value) {
                var settable = value.ChangeTypeTo<int>();
                this.GetType().GetProperty(this.KeyName()).SetValue(this, settable, null);
            }
        }
        
        public override string ToString(){
                            return this.nazwa.ToString();
                    }

        public override bool Equals(object obj){
            if(obj.GetType()==typeof(marketing_projekty)){
                marketing_projekty compare=(marketing_projekty)obj;
                return compare.KeyValue()==this.KeyValue();
            }else{
                return base.Equals(obj);
            }
        }

        
        public override int GetHashCode() {
            return this.idprojekt;
        }
        
        public string DescriptorValue()
        {
                            return this.nazwa.ToString();
                    }

        public string DescriptorColumn() {
            return "nazwa";
        }
        public static string GetKeyColumn()
        {
            return "idprojekt";
        }        
        public static string GetDescriptorColumn()
        {
            return "nazwa";
        }
        
        #region ' Foreign Keys '
        #endregion
        

        int _idprojekt;
        public int idprojekt
        {
            get { return _idprojekt; }
            set
            {
                if(_idprojekt!=value){
                    _idprojekt=value;
                    var col=tbl.Columns.SingleOrDefault(x=>x.Name=="idprojekt");
                    if(col!=null){
                        if(!_dirtyColumns.Any(x=>x.Name==col.Name) && _isLoaded){
                            _dirtyColumns.Add(col);
                        }
                    }
                    OnChanged();
                }
            }
        }

        string _nazwa;
        public string nazwa
        {
            get { return _nazwa; }
            set
            {
                if(_nazwa!=value){
                    _nazwa=value;
                    var col=tbl.Columns.SingleOrDefault(x=>x.Name=="nazwa");
                    if(col!=null){
                        if(!_dirtyColumns.Any(x=>x.Name==col.Name) && _isLoaded){
                            _dirtyColumns.Add(col);
                        }
                    }
                    OnChanged();
                }
            }
        }

        string _rodzaj;
        public string rodzaj
        {
            get { return _rodzaj; }
            set
            {
                if(_rodzaj!=value){
                    _rodzaj=value;
                    var col=tbl.Columns.SingleOrDefault(x=>x.Name=="rodzaj");
                    if(col!=null){
                        if(!_dirtyColumns.Any(x=>x.Name==col.Name) && _isLoaded){
                            _dirtyColumns.Add(col);
                        }
                    }
                    OnChanged();
                }
            }
        }

        string _opis;
        public string opis
        {
            get { return _opis; }
            set
            {
                if(_opis!=value){
                    _opis=value;
                    var col=tbl.Columns.SingleOrDefault(x=>x.Name=="opis");
                    if(col!=null){
                        if(!_dirtyColumns.Any(x=>x.Name==col.Name) && _isLoaded){
                            _dirtyColumns.Add(col);
                        }
                    }
                    OnChanged();
                }
            }
        }

        string _budzet;
        public string budzet
        {
            get { return _budzet; }
            set
            {
                if(_budzet!=value){
                    _budzet=value;
                    var col=tbl.Columns.SingleOrDefault(x=>x.Name=="budzet");
                    if(col!=null){
                        if(!_dirtyColumns.Any(x=>x.Name==col.Name) && _isLoaded){
                            _dirtyColumns.Add(col);
                        }
                    }
                    OnChanged();
                }
            }
        }

        string _realizacja;
        public string realizacja
        {
            get { return _realizacja; }
            set
            {
                if(_realizacja!=value){
                    _realizacja=value;
                    var col=tbl.Columns.SingleOrDefault(x=>x.Name=="realizacja");
                    if(col!=null){
                        if(!_dirtyColumns.Any(x=>x.Name==col.Name) && _isLoaded){
                            _dirtyColumns.Add(col);
                        }
                    }
                    OnChanged();
                }
            }
        }

        string _status;
        public string status
        {
            get { return _status; }
            set
            {
                if(_status!=value){
                    _status=value;
                    var col=tbl.Columns.SingleOrDefault(x=>x.Name=="status");
                    if(col!=null){
                        if(!_dirtyColumns.Any(x=>x.Name==col.Name) && _isLoaded){
                            _dirtyColumns.Add(col);
                        }
                    }
                    OnChanged();
                }
            }
        }



        public DbCommand GetUpdateCommand() {
            if(TestMode)
                return _db.DataProvider.CreateCommand();
            else
                return this.ToUpdateQuery(_db.Provider).GetCommand().ToDbCommand();
            
        }
        public DbCommand GetInsertCommand() {
 
            if(TestMode)
                return _db.DataProvider.CreateCommand();
            else
                return this.ToInsertQuery(_db.Provider).GetCommand().ToDbCommand();
        }
        
        public DbCommand GetDeleteCommand() {
            if(TestMode)
                return _db.DataProvider.CreateCommand();
            else
                return this.ToDeleteQuery(_db.Provider).GetCommand().ToDbCommand();
        }
       
        
        public void Update(){
            Update(_db.DataProvider);
        }
        
        public void Update(IDataProvider provider){
        
            
            if(this._dirtyColumns.Count>0){
                _repo.Update(this,provider);
                _dirtyColumns.Clear();    
            }
            OnSaved();
       }
 
        public void Add(){
            Add(_db.DataProvider);
        }
        
        
       
        public void Add(IDataProvider provider){

            
            var key=KeyValue();
            if(key==null){
                var newKey=_repo.Add(this,provider);
                this.SetKeyValue(newKey);
            }else{
                _repo.Add(this,provider);
            }
            SetIsNew(false);
            OnSaved();
        }
        
                
        
        public void Save() {
            Save(_db.DataProvider);
        }      
        public void Save(IDataProvider provider) {
            
           
            if (_isNew) {
                Add(provider);
                
            } else {
                Update(provider);
            }
            
        }

        

        public void Delete(IDataProvider provider) {
                   
                 
            _repo.Delete(KeyValue());
            
                    }


        public void Delete() {
            Delete(_db.DataProvider);
        }


        public static void Delete(Expression<Func<marketing_projekty, bool>> expression) {
            var repo = GetRepo();
            
       
            
            repo.DeleteMany(expression);
            
        }

        

        public void Load(IDataReader rdr) {
            Load(rdr, true);
        }
        public void Load(IDataReader rdr, bool closeReader) {
            if (rdr.Read()) {

                try {
                    rdr.Load(this);
                    SetIsNew(false);
                    SetIsLoaded(true);
                } catch {
                    SetIsLoaded(false);
                    throw;
                }
            }else{
                SetIsLoaded(false);
            }

            if (closeReader)
                rdr.Dispose();
        }
        

    } 
    
    
    /// <summary>
    /// A class which represents the s_prelegent table in the evolution Database.
    /// </summary>
    public partial class s_prelegent: IActiveRecord
    {
    
        #region Built-in testing
        static TestRepository<s_prelegent> _testRepo;
        

        
        static void SetTestRepo(){
            _testRepo = _testRepo ?? new TestRepository<s_prelegent>(new Amortyzacje.Model.evolutionDB());
        }
        public static void ResetTestRepo(){
            _testRepo = null;
            SetTestRepo();
        }
        public static void Setup(List<s_prelegent> testlist){
            SetTestRepo();
            foreach (var item in testlist)
            {
                _testRepo._items.Add(item);
            }
        }
        public static void Setup(s_prelegent item) {
            SetTestRepo();
            _testRepo._items.Add(item);
        }
        public static void Setup(int testItems) {
            SetTestRepo();
            for(int i=0;i<testItems;i++){
                s_prelegent item=new s_prelegent();
                _testRepo._items.Add(item);
            }
        }
        
        public bool TestMode = false;


        #endregion

        IRepository<s_prelegent> _repo;
        ITable tbl;
        bool _isNew;
        public bool IsNew(){
            return _isNew;
        }
        
        public void SetIsLoaded(bool isLoaded){
            _isLoaded=isLoaded;
            if(isLoaded)
                OnLoaded();
        }
        
        public void SetIsNew(bool isNew){
            _isNew=isNew;
        }
        bool _isLoaded;
        public bool IsLoaded(){
            return _isLoaded;
        }
                
        List<IColumn> _dirtyColumns;
        public bool IsDirty(){
            return _dirtyColumns.Count>0;
        }
        
        public List<IColumn> GetDirtyColumns (){
            return _dirtyColumns;
        }

        Amortyzacje.Model.evolutionDB _db;
        public s_prelegent(string connectionString, string providerName) {

            _db=new Amortyzacje.Model.evolutionDB(connectionString, providerName);
            Init();            
         }
        void Init(){
            TestMode=this._db.DataProvider.ConnectionString.Equals("test", StringComparison.InvariantCultureIgnoreCase);
            _dirtyColumns=new List<IColumn>();
            if(TestMode){
                s_prelegent.SetTestRepo();
                _repo=_testRepo;
            }else{
                _repo = new SubSonicRepository<s_prelegent>(_db);
            }
            tbl=_repo.GetTable();
            SetIsNew(true);
            OnCreated();       

        }
        
        public s_prelegent(){
             _db=new Amortyzacje.Model.evolutionDB();
            Init();            
        }
        
       
        partial void OnCreated();
            
        partial void OnLoaded();
        
        partial void OnSaved();
        
        partial void OnChanged();
        
        public IList<IColumn> Columns{
            get{
                return tbl.Columns;
            }
        }

        public s_prelegent(Expression<Func<s_prelegent, bool>> expression):this() {

            SetIsLoaded(_repo.Load(this,expression));
        }
        
       
        
        internal static IRepository<s_prelegent> GetRepo(string connectionString, string providerName){
            Amortyzacje.Model.evolutionDB db;
            if(String.IsNullOrEmpty(connectionString)){
                db=new Amortyzacje.Model.evolutionDB();
            }else{
                db=new Amortyzacje.Model.evolutionDB(connectionString, providerName);
            }
            IRepository<s_prelegent> _repo;
            
            if(db.TestMode){
                s_prelegent.SetTestRepo();
                _repo=_testRepo;
            }else{
                _repo = new SubSonicRepository<s_prelegent>(db);
            }
            return _repo;        
        }       
        
        internal static IRepository<s_prelegent> GetRepo(){
            return GetRepo("","");
        }
        
        public static s_prelegent SingleOrDefault(Expression<Func<s_prelegent, bool>> expression) {

            var repo = GetRepo();
            var results=repo.Find(expression);
            s_prelegent single=null;
            if(results.Count() > 0){
                single=results.ToList()[0];
                single.OnLoaded();
                single.SetIsLoaded(true);
                single.SetIsNew(false);
            }

            return single;
        }      
        
        public static s_prelegent SingleOrDefault(Expression<Func<s_prelegent, bool>> expression,string connectionString, string providerName) {
            var repo = GetRepo(connectionString,providerName);
            var results=repo.Find(expression);
            s_prelegent single=null;
            if(results.Count() > 0){
                single=results.ToList()[0];
            }

            return single;


        }
        
        
        public static bool Exists(Expression<Func<s_prelegent, bool>> expression,string connectionString, string providerName) {
           
            return All(connectionString,providerName).Any(expression);
        }        
        public static bool Exists(Expression<Func<s_prelegent, bool>> expression) {
           
            return All().Any(expression);
        }        

        public static IList<s_prelegent> Find(Expression<Func<s_prelegent, bool>> expression) {
            
            var repo = GetRepo();
            return repo.Find(expression).ToList();
        }
        
        public static IList<s_prelegent> Find(Expression<Func<s_prelegent, bool>> expression,string connectionString, string providerName) {

            var repo = GetRepo(connectionString,providerName);
            return repo.Find(expression).ToList();

        }
        public static IQueryable<s_prelegent> All(string connectionString, string providerName) {
            return GetRepo(connectionString,providerName).GetAll();
        }
        public static IQueryable<s_prelegent> All() {
            return GetRepo().GetAll();
        }
        
        public static PagedList<s_prelegent> GetPaged(string sortBy, int pageIndex, int pageSize,string connectionString, string providerName) {
            return GetRepo(connectionString,providerName).GetPaged(sortBy, pageIndex, pageSize);
        }
      
        public static PagedList<s_prelegent> GetPaged(string sortBy, int pageIndex, int pageSize) {
            return GetRepo().GetPaged(sortBy, pageIndex, pageSize);
        }

        public static PagedList<s_prelegent> GetPaged(int pageIndex, int pageSize,string connectionString, string providerName) {
            return GetRepo(connectionString,providerName).GetPaged(pageIndex, pageSize);
            
        }


        public static PagedList<s_prelegent> GetPaged(int pageIndex, int pageSize) {
            return GetRepo().GetPaged(pageIndex, pageSize);
            
        }

        public string KeyName()
        {
            return "id";
        }

        public object KeyValue()
        {
            return this.id;
        }
        
        public void SetKeyValue(object value) {
            if (value != null && value!=DBNull.Value) {
                var settable = value.ChangeTypeTo<int>();
                this.GetType().GetProperty(this.KeyName()).SetValue(this, settable, null);
            }
        }
        
        public override string ToString(){
                            return this.id_szkol.ToString();
                    }

        public override bool Equals(object obj){
            if(obj.GetType()==typeof(s_prelegent)){
                s_prelegent compare=(s_prelegent)obj;
                return compare.KeyValue()==this.KeyValue();
            }else{
                return base.Equals(obj);
            }
        }

        
        public override int GetHashCode() {
            return this.id;
        }
        
        public string DescriptorValue()
        {
                            return this.id_szkol.ToString();
                    }

        public string DescriptorColumn() {
            return "id_szkol";
        }
        public static string GetKeyColumn()
        {
            return "id";
        }        
        public static string GetDescriptorColumn()
        {
            return "id_szkol";
        }
        
        #region ' Foreign Keys '
        #endregion
        

        int _id;
        public int id
        {
            get { return _id; }
            set
            {
                if(_id!=value){
                    _id=value;
                    var col=tbl.Columns.SingleOrDefault(x=>x.Name=="id");
                    if(col!=null){
                        if(!_dirtyColumns.Any(x=>x.Name==col.Name) && _isLoaded){
                            _dirtyColumns.Add(col);
                        }
                    }
                    OnChanged();
                }
            }
        }

        int _id_szkol;
        public int id_szkol
        {
            get { return _id_szkol; }
            set
            {
                if(_id_szkol!=value){
                    _id_szkol=value;
                    var col=tbl.Columns.SingleOrDefault(x=>x.Name=="id_szkol");
                    if(col!=null){
                        if(!_dirtyColumns.Any(x=>x.Name==col.Name) && _isLoaded){
                            _dirtyColumns.Add(col);
                        }
                    }
                    OnChanged();
                }
            }
        }

        int _id_prel;
        public int id_prel
        {
            get { return _id_prel; }
            set
            {
                if(_id_prel!=value){
                    _id_prel=value;
                    var col=tbl.Columns.SingleOrDefault(x=>x.Name=="id_prel");
                    if(col!=null){
                        if(!_dirtyColumns.Any(x=>x.Name==col.Name) && _isLoaded){
                            _dirtyColumns.Add(col);
                        }
                    }
                    OnChanged();
                }
            }
        }

        long? _time_from;
        public long? time_from
        {
            get { return _time_from; }
            set
            {
                if(_time_from!=value){
                    _time_from=value;
                    var col=tbl.Columns.SingleOrDefault(x=>x.Name=="time_from");
                    if(col!=null){
                        if(!_dirtyColumns.Any(x=>x.Name==col.Name) && _isLoaded){
                            _dirtyColumns.Add(col);
                        }
                    }
                    OnChanged();
                }
            }
        }

        long? _time_till;
        public long? time_till
        {
            get { return _time_till; }
            set
            {
                if(_time_till!=value){
                    _time_till=value;
                    var col=tbl.Columns.SingleOrDefault(x=>x.Name=="time_till");
                    if(col!=null){
                        if(!_dirtyColumns.Any(x=>x.Name==col.Name) && _isLoaded){
                            _dirtyColumns.Add(col);
                        }
                    }
                    OnChanged();
                }
            }
        }



        public DbCommand GetUpdateCommand() {
            if(TestMode)
                return _db.DataProvider.CreateCommand();
            else
                return this.ToUpdateQuery(_db.Provider).GetCommand().ToDbCommand();
            
        }
        public DbCommand GetInsertCommand() {
 
            if(TestMode)
                return _db.DataProvider.CreateCommand();
            else
                return this.ToInsertQuery(_db.Provider).GetCommand().ToDbCommand();
        }
        
        public DbCommand GetDeleteCommand() {
            if(TestMode)
                return _db.DataProvider.CreateCommand();
            else
                return this.ToDeleteQuery(_db.Provider).GetCommand().ToDbCommand();
        }
       
        
        public void Update(){
            Update(_db.DataProvider);
        }
        
        public void Update(IDataProvider provider){
        
            
            if(this._dirtyColumns.Count>0){
                _repo.Update(this,provider);
                _dirtyColumns.Clear();    
            }
            OnSaved();
       }
 
        public void Add(){
            Add(_db.DataProvider);
        }
        
        
       
        public void Add(IDataProvider provider){

            
            var key=KeyValue();
            if(key==null){
                var newKey=_repo.Add(this,provider);
                this.SetKeyValue(newKey);
            }else{
                _repo.Add(this,provider);
            }
            SetIsNew(false);
            OnSaved();
        }
        
                
        
        public void Save() {
            Save(_db.DataProvider);
        }      
        public void Save(IDataProvider provider) {
            
           
            if (_isNew) {
                Add(provider);
                
            } else {
                Update(provider);
            }
            
        }

        

        public void Delete(IDataProvider provider) {
                   
                 
            _repo.Delete(KeyValue());
            
                    }


        public void Delete() {
            Delete(_db.DataProvider);
        }


        public static void Delete(Expression<Func<s_prelegent, bool>> expression) {
            var repo = GetRepo();
            
       
            
            repo.DeleteMany(expression);
            
        }

        

        public void Load(IDataReader rdr) {
            Load(rdr, true);
        }
        public void Load(IDataReader rdr, bool closeReader) {
            if (rdr.Read()) {

                try {
                    rdr.Load(this);
                    SetIsNew(false);
                    SetIsLoaded(true);
                } catch {
                    SetIsLoaded(false);
                    throw;
                }
            }else{
                SetIsLoaded(false);
            }

            if (closeReader)
                rdr.Dispose();
        }
        

    } 
    
    
    /// <summary>
    /// A class which represents the s_sala table in the evolution Database.
    /// </summary>
    public partial class s_sala: IActiveRecord
    {
    
        #region Built-in testing
        static TestRepository<s_sala> _testRepo;
        

        
        static void SetTestRepo(){
            _testRepo = _testRepo ?? new TestRepository<s_sala>(new Amortyzacje.Model.evolutionDB());
        }
        public static void ResetTestRepo(){
            _testRepo = null;
            SetTestRepo();
        }
        public static void Setup(List<s_sala> testlist){
            SetTestRepo();
            foreach (var item in testlist)
            {
                _testRepo._items.Add(item);
            }
        }
        public static void Setup(s_sala item) {
            SetTestRepo();
            _testRepo._items.Add(item);
        }
        public static void Setup(int testItems) {
            SetTestRepo();
            for(int i=0;i<testItems;i++){
                s_sala item=new s_sala();
                _testRepo._items.Add(item);
            }
        }
        
        public bool TestMode = false;


        #endregion

        IRepository<s_sala> _repo;
        ITable tbl;
        bool _isNew;
        public bool IsNew(){
            return _isNew;
        }
        
        public void SetIsLoaded(bool isLoaded){
            _isLoaded=isLoaded;
            if(isLoaded)
                OnLoaded();
        }
        
        public void SetIsNew(bool isNew){
            _isNew=isNew;
        }
        bool _isLoaded;
        public bool IsLoaded(){
            return _isLoaded;
        }
                
        List<IColumn> _dirtyColumns;
        public bool IsDirty(){
            return _dirtyColumns.Count>0;
        }
        
        public List<IColumn> GetDirtyColumns (){
            return _dirtyColumns;
        }

        Amortyzacje.Model.evolutionDB _db;
        public s_sala(string connectionString, string providerName) {

            _db=new Amortyzacje.Model.evolutionDB(connectionString, providerName);
            Init();            
         }
        void Init(){
            TestMode=this._db.DataProvider.ConnectionString.Equals("test", StringComparison.InvariantCultureIgnoreCase);
            _dirtyColumns=new List<IColumn>();
            if(TestMode){
                s_sala.SetTestRepo();
                _repo=_testRepo;
            }else{
                _repo = new SubSonicRepository<s_sala>(_db);
            }
            tbl=_repo.GetTable();
            SetIsNew(true);
            OnCreated();       

        }
        
        public s_sala(){
             _db=new Amortyzacje.Model.evolutionDB();
            Init();            
        }
        
       
        partial void OnCreated();
            
        partial void OnLoaded();
        
        partial void OnSaved();
        
        partial void OnChanged();
        
        public IList<IColumn> Columns{
            get{
                return tbl.Columns;
            }
        }

        public s_sala(Expression<Func<s_sala, bool>> expression):this() {

            SetIsLoaded(_repo.Load(this,expression));
        }
        
       
        
        internal static IRepository<s_sala> GetRepo(string connectionString, string providerName){
            Amortyzacje.Model.evolutionDB db;
            if(String.IsNullOrEmpty(connectionString)){
                db=new Amortyzacje.Model.evolutionDB();
            }else{
                db=new Amortyzacje.Model.evolutionDB(connectionString, providerName);
            }
            IRepository<s_sala> _repo;
            
            if(db.TestMode){
                s_sala.SetTestRepo();
                _repo=_testRepo;
            }else{
                _repo = new SubSonicRepository<s_sala>(db);
            }
            return _repo;        
        }       
        
        internal static IRepository<s_sala> GetRepo(){
            return GetRepo("","");
        }
        
        public static s_sala SingleOrDefault(Expression<Func<s_sala, bool>> expression) {

            var repo = GetRepo();
            var results=repo.Find(expression);
            s_sala single=null;
            if(results.Count() > 0){
                single=results.ToList()[0];
                single.OnLoaded();
                single.SetIsLoaded(true);
                single.SetIsNew(false);
            }

            return single;
        }      
        
        public static s_sala SingleOrDefault(Expression<Func<s_sala, bool>> expression,string connectionString, string providerName) {
            var repo = GetRepo(connectionString,providerName);
            var results=repo.Find(expression);
            s_sala single=null;
            if(results.Count() > 0){
                single=results.ToList()[0];
            }

            return single;


        }
        
        
        public static bool Exists(Expression<Func<s_sala, bool>> expression,string connectionString, string providerName) {
           
            return All(connectionString,providerName).Any(expression);
        }        
        public static bool Exists(Expression<Func<s_sala, bool>> expression) {
           
            return All().Any(expression);
        }        

        public static IList<s_sala> Find(Expression<Func<s_sala, bool>> expression) {
            
            var repo = GetRepo();
            return repo.Find(expression).ToList();
        }
        
        public static IList<s_sala> Find(Expression<Func<s_sala, bool>> expression,string connectionString, string providerName) {

            var repo = GetRepo(connectionString,providerName);
            return repo.Find(expression).ToList();

        }
        public static IQueryable<s_sala> All(string connectionString, string providerName) {
            return GetRepo(connectionString,providerName).GetAll();
        }
        public static IQueryable<s_sala> All() {
            return GetRepo().GetAll();
        }
        
        public static PagedList<s_sala> GetPaged(string sortBy, int pageIndex, int pageSize,string connectionString, string providerName) {
            return GetRepo(connectionString,providerName).GetPaged(sortBy, pageIndex, pageSize);
        }
      
        public static PagedList<s_sala> GetPaged(string sortBy, int pageIndex, int pageSize) {
            return GetRepo().GetPaged(sortBy, pageIndex, pageSize);
        }

        public static PagedList<s_sala> GetPaged(int pageIndex, int pageSize,string connectionString, string providerName) {
            return GetRepo(connectionString,providerName).GetPaged(pageIndex, pageSize);
            
        }


        public static PagedList<s_sala> GetPaged(int pageIndex, int pageSize) {
            return GetRepo().GetPaged(pageIndex, pageSize);
            
        }

        public string KeyName()
        {
            return "id";
        }

        public object KeyValue()
        {
            return this.id;
        }
        
        public void SetKeyValue(object value) {
            if (value != null && value!=DBNull.Value) {
                var settable = value.ChangeTypeTo<int>();
                this.GetType().GetProperty(this.KeyName()).SetValue(this, settable, null);
            }
        }
        
        public override string ToString(){
                            return this.id_sala.ToString();
                    }

        public override bool Equals(object obj){
            if(obj.GetType()==typeof(s_sala)){
                s_sala compare=(s_sala)obj;
                return compare.KeyValue()==this.KeyValue();
            }else{
                return base.Equals(obj);
            }
        }

        
        public override int GetHashCode() {
            return this.id;
        }
        
        public string DescriptorValue()
        {
                            return this.id_sala.ToString();
                    }

        public string DescriptorColumn() {
            return "id_sala";
        }
        public static string GetKeyColumn()
        {
            return "id";
        }        
        public static string GetDescriptorColumn()
        {
            return "id_sala";
        }
        
        #region ' Foreign Keys '
        #endregion
        

        int _id;
        public int id
        {
            get { return _id; }
            set
            {
                if(_id!=value){
                    _id=value;
                    var col=tbl.Columns.SingleOrDefault(x=>x.Name=="id");
                    if(col!=null){
                        if(!_dirtyColumns.Any(x=>x.Name==col.Name) && _isLoaded){
                            _dirtyColumns.Add(col);
                        }
                    }
                    OnChanged();
                }
            }
        }

        int _id_sala;
        public int id_sala
        {
            get { return _id_sala; }
            set
            {
                if(_id_sala!=value){
                    _id_sala=value;
                    var col=tbl.Columns.SingleOrDefault(x=>x.Name=="id_sala");
                    if(col!=null){
                        if(!_dirtyColumns.Any(x=>x.Name==col.Name) && _isLoaded){
                            _dirtyColumns.Add(col);
                        }
                    }
                    OnChanged();
                }
            }
        }

        int _id_szkol;
        public int id_szkol
        {
            get { return _id_szkol; }
            set
            {
                if(_id_szkol!=value){
                    _id_szkol=value;
                    var col=tbl.Columns.SingleOrDefault(x=>x.Name=="id_szkol");
                    if(col!=null){
                        if(!_dirtyColumns.Any(x=>x.Name==col.Name) && _isLoaded){
                            _dirtyColumns.Add(col);
                        }
                    }
                    OnChanged();
                }
            }
        }

        long _time_from;
        public long time_from
        {
            get { return _time_from; }
            set
            {
                if(_time_from!=value){
                    _time_from=value;
                    var col=tbl.Columns.SingleOrDefault(x=>x.Name=="time_from");
                    if(col!=null){
                        if(!_dirtyColumns.Any(x=>x.Name==col.Name) && _isLoaded){
                            _dirtyColumns.Add(col);
                        }
                    }
                    OnChanged();
                }
            }
        }

        long _time_till;
        public long time_till
        {
            get { return _time_till; }
            set
            {
                if(_time_till!=value){
                    _time_till=value;
                    var col=tbl.Columns.SingleOrDefault(x=>x.Name=="time_till");
                    if(col!=null){
                        if(!_dirtyColumns.Any(x=>x.Name==col.Name) && _isLoaded){
                            _dirtyColumns.Add(col);
                        }
                    }
                    OnChanged();
                }
            }
        }



        public DbCommand GetUpdateCommand() {
            if(TestMode)
                return _db.DataProvider.CreateCommand();
            else
                return this.ToUpdateQuery(_db.Provider).GetCommand().ToDbCommand();
            
        }
        public DbCommand GetInsertCommand() {
 
            if(TestMode)
                return _db.DataProvider.CreateCommand();
            else
                return this.ToInsertQuery(_db.Provider).GetCommand().ToDbCommand();
        }
        
        public DbCommand GetDeleteCommand() {
            if(TestMode)
                return _db.DataProvider.CreateCommand();
            else
                return this.ToDeleteQuery(_db.Provider).GetCommand().ToDbCommand();
        }
       
        
        public void Update(){
            Update(_db.DataProvider);
        }
        
        public void Update(IDataProvider provider){
        
            
            if(this._dirtyColumns.Count>0){
                _repo.Update(this,provider);
                _dirtyColumns.Clear();    
            }
            OnSaved();
       }
 
        public void Add(){
            Add(_db.DataProvider);
        }
        
        
       
        public void Add(IDataProvider provider){

            
            var key=KeyValue();
            if(key==null){
                var newKey=_repo.Add(this,provider);
                this.SetKeyValue(newKey);
            }else{
                _repo.Add(this,provider);
            }
            SetIsNew(false);
            OnSaved();
        }
        
                
        
        public void Save() {
            Save(_db.DataProvider);
        }      
        public void Save(IDataProvider provider) {
            
           
            if (_isNew) {
                Add(provider);
                
            } else {
                Update(provider);
            }
            
        }

        

        public void Delete(IDataProvider provider) {
                   
                 
            _repo.Delete(KeyValue());
            
                    }


        public void Delete() {
            Delete(_db.DataProvider);
        }


        public static void Delete(Expression<Func<s_sala, bool>> expression) {
            var repo = GetRepo();
            
       
            
            repo.DeleteMany(expression);
            
        }

        

        public void Load(IDataReader rdr) {
            Load(rdr, true);
        }
        public void Load(IDataReader rdr, bool closeReader) {
            if (rdr.Read()) {

                try {
                    rdr.Load(this);
                    SetIsNew(false);
                    SetIsLoaded(true);
                } catch {
                    SetIsLoaded(false);
                    throw;
                }
            }else{
                SetIsLoaded(false);
            }

            if (closeReader)
                rdr.Dispose();
        }
        

    } 
    
    
    /// <summary>
    /// A class which represents the s_sprzet table in the evolution Database.
    /// </summary>
    public partial class s_sprzet: IActiveRecord
    {
    
        #region Built-in testing
        static TestRepository<s_sprzet> _testRepo;
        

        
        static void SetTestRepo(){
            _testRepo = _testRepo ?? new TestRepository<s_sprzet>(new Amortyzacje.Model.evolutionDB());
        }
        public static void ResetTestRepo(){
            _testRepo = null;
            SetTestRepo();
        }
        public static void Setup(List<s_sprzet> testlist){
            SetTestRepo();
            foreach (var item in testlist)
            {
                _testRepo._items.Add(item);
            }
        }
        public static void Setup(s_sprzet item) {
            SetTestRepo();
            _testRepo._items.Add(item);
        }
        public static void Setup(int testItems) {
            SetTestRepo();
            for(int i=0;i<testItems;i++){
                s_sprzet item=new s_sprzet();
                _testRepo._items.Add(item);
            }
        }
        
        public bool TestMode = false;


        #endregion

        IRepository<s_sprzet> _repo;
        ITable tbl;
        bool _isNew;
        public bool IsNew(){
            return _isNew;
        }
        
        public void SetIsLoaded(bool isLoaded){
            _isLoaded=isLoaded;
            if(isLoaded)
                OnLoaded();
        }
        
        public void SetIsNew(bool isNew){
            _isNew=isNew;
        }
        bool _isLoaded;
        public bool IsLoaded(){
            return _isLoaded;
        }
                
        List<IColumn> _dirtyColumns;
        public bool IsDirty(){
            return _dirtyColumns.Count>0;
        }
        
        public List<IColumn> GetDirtyColumns (){
            return _dirtyColumns;
        }

        Amortyzacje.Model.evolutionDB _db;
        public s_sprzet(string connectionString, string providerName) {

            _db=new Amortyzacje.Model.evolutionDB(connectionString, providerName);
            Init();            
         }
        void Init(){
            TestMode=this._db.DataProvider.ConnectionString.Equals("test", StringComparison.InvariantCultureIgnoreCase);
            _dirtyColumns=new List<IColumn>();
            if(TestMode){
                s_sprzet.SetTestRepo();
                _repo=_testRepo;
            }else{
                _repo = new SubSonicRepository<s_sprzet>(_db);
            }
            tbl=_repo.GetTable();
            SetIsNew(true);
            OnCreated();       

        }
        
        public s_sprzet(){
             _db=new Amortyzacje.Model.evolutionDB();
            Init();            
        }
        
       
        partial void OnCreated();
            
        partial void OnLoaded();
        
        partial void OnSaved();
        
        partial void OnChanged();
        
        public IList<IColumn> Columns{
            get{
                return tbl.Columns;
            }
        }

        public s_sprzet(Expression<Func<s_sprzet, bool>> expression):this() {

            SetIsLoaded(_repo.Load(this,expression));
        }
        
       
        
        internal static IRepository<s_sprzet> GetRepo(string connectionString, string providerName){
            Amortyzacje.Model.evolutionDB db;
            if(String.IsNullOrEmpty(connectionString)){
                db=new Amortyzacje.Model.evolutionDB();
            }else{
                db=new Amortyzacje.Model.evolutionDB(connectionString, providerName);
            }
            IRepository<s_sprzet> _repo;
            
            if(db.TestMode){
                s_sprzet.SetTestRepo();
                _repo=_testRepo;
            }else{
                _repo = new SubSonicRepository<s_sprzet>(db);
            }
            return _repo;        
        }       
        
        internal static IRepository<s_sprzet> GetRepo(){
            return GetRepo("","");
        }
        
        public static s_sprzet SingleOrDefault(Expression<Func<s_sprzet, bool>> expression) {

            var repo = GetRepo();
            var results=repo.Find(expression);
            s_sprzet single=null;
            if(results.Count() > 0){
                single=results.ToList()[0];
                single.OnLoaded();
                single.SetIsLoaded(true);
                single.SetIsNew(false);
            }

            return single;
        }      
        
        public static s_sprzet SingleOrDefault(Expression<Func<s_sprzet, bool>> expression,string connectionString, string providerName) {
            var repo = GetRepo(connectionString,providerName);
            var results=repo.Find(expression);
            s_sprzet single=null;
            if(results.Count() > 0){
                single=results.ToList()[0];
            }

            return single;


        }
        
        
        public static bool Exists(Expression<Func<s_sprzet, bool>> expression,string connectionString, string providerName) {
           
            return All(connectionString,providerName).Any(expression);
        }        
        public static bool Exists(Expression<Func<s_sprzet, bool>> expression) {
           
            return All().Any(expression);
        }        

        public static IList<s_sprzet> Find(Expression<Func<s_sprzet, bool>> expression) {
            
            var repo = GetRepo();
            return repo.Find(expression).ToList();
        }
        
        public static IList<s_sprzet> Find(Expression<Func<s_sprzet, bool>> expression,string connectionString, string providerName) {

            var repo = GetRepo(connectionString,providerName);
            return repo.Find(expression).ToList();

        }
        public static IQueryable<s_sprzet> All(string connectionString, string providerName) {
            return GetRepo(connectionString,providerName).GetAll();
        }
        public static IQueryable<s_sprzet> All() {
            return GetRepo().GetAll();
        }
        
        public static PagedList<s_sprzet> GetPaged(string sortBy, int pageIndex, int pageSize,string connectionString, string providerName) {
            return GetRepo(connectionString,providerName).GetPaged(sortBy, pageIndex, pageSize);
        }
      
        public static PagedList<s_sprzet> GetPaged(string sortBy, int pageIndex, int pageSize) {
            return GetRepo().GetPaged(sortBy, pageIndex, pageSize);
        }

        public static PagedList<s_sprzet> GetPaged(int pageIndex, int pageSize,string connectionString, string providerName) {
            return GetRepo(connectionString,providerName).GetPaged(pageIndex, pageSize);
            
        }


        public static PagedList<s_sprzet> GetPaged(int pageIndex, int pageSize) {
            return GetRepo().GetPaged(pageIndex, pageSize);
            
        }

        public string KeyName()
        {
            return "id";
        }

        public object KeyValue()
        {
            return this.id;
        }
        
        public void SetKeyValue(object value) {
            if (value != null && value!=DBNull.Value) {
                var settable = value.ChangeTypeTo<int>();
                this.GetType().GetProperty(this.KeyName()).SetValue(this, settable, null);
            }
        }
        
        public override string ToString(){
                            return this.id_szkol.ToString();
                    }

        public override bool Equals(object obj){
            if(obj.GetType()==typeof(s_sprzet)){
                s_sprzet compare=(s_sprzet)obj;
                return compare.KeyValue()==this.KeyValue();
            }else{
                return base.Equals(obj);
            }
        }

        
        public override int GetHashCode() {
            return this.id;
        }
        
        public string DescriptorValue()
        {
                            return this.id_szkol.ToString();
                    }

        public string DescriptorColumn() {
            return "id_szkol";
        }
        public static string GetKeyColumn()
        {
            return "id";
        }        
        public static string GetDescriptorColumn()
        {
            return "id_szkol";
        }
        
        #region ' Foreign Keys '
        #endregion
        

        int _id;
        public int id
        {
            get { return _id; }
            set
            {
                if(_id!=value){
                    _id=value;
                    var col=tbl.Columns.SingleOrDefault(x=>x.Name=="id");
                    if(col!=null){
                        if(!_dirtyColumns.Any(x=>x.Name==col.Name) && _isLoaded){
                            _dirtyColumns.Add(col);
                        }
                    }
                    OnChanged();
                }
            }
        }

        int _id_szkol;
        public int id_szkol
        {
            get { return _id_szkol; }
            set
            {
                if(_id_szkol!=value){
                    _id_szkol=value;
                    var col=tbl.Columns.SingleOrDefault(x=>x.Name=="id_szkol");
                    if(col!=null){
                        if(!_dirtyColumns.Any(x=>x.Name==col.Name) && _isLoaded){
                            _dirtyColumns.Add(col);
                        }
                    }
                    OnChanged();
                }
            }
        }

        int _id_sprzet;
        public int id_sprzet
        {
            get { return _id_sprzet; }
            set
            {
                if(_id_sprzet!=value){
                    _id_sprzet=value;
                    var col=tbl.Columns.SingleOrDefault(x=>x.Name=="id_sprzet");
                    if(col!=null){
                        if(!_dirtyColumns.Any(x=>x.Name==col.Name) && _isLoaded){
                            _dirtyColumns.Add(col);
                        }
                    }
                    OnChanged();
                }
            }
        }

        long? _time_from;
        public long? time_from
        {
            get { return _time_from; }
            set
            {
                if(_time_from!=value){
                    _time_from=value;
                    var col=tbl.Columns.SingleOrDefault(x=>x.Name=="time_from");
                    if(col!=null){
                        if(!_dirtyColumns.Any(x=>x.Name==col.Name) && _isLoaded){
                            _dirtyColumns.Add(col);
                        }
                    }
                    OnChanged();
                }
            }
        }

        long? _time_till;
        public long? time_till
        {
            get { return _time_till; }
            set
            {
                if(_time_till!=value){
                    _time_till=value;
                    var col=tbl.Columns.SingleOrDefault(x=>x.Name=="time_till");
                    if(col!=null){
                        if(!_dirtyColumns.Any(x=>x.Name==col.Name) && _isLoaded){
                            _dirtyColumns.Add(col);
                        }
                    }
                    OnChanged();
                }
            }
        }



        public DbCommand GetUpdateCommand() {
            if(TestMode)
                return _db.DataProvider.CreateCommand();
            else
                return this.ToUpdateQuery(_db.Provider).GetCommand().ToDbCommand();
            
        }
        public DbCommand GetInsertCommand() {
 
            if(TestMode)
                return _db.DataProvider.CreateCommand();
            else
                return this.ToInsertQuery(_db.Provider).GetCommand().ToDbCommand();
        }
        
        public DbCommand GetDeleteCommand() {
            if(TestMode)
                return _db.DataProvider.CreateCommand();
            else
                return this.ToDeleteQuery(_db.Provider).GetCommand().ToDbCommand();
        }
       
        
        public void Update(){
            Update(_db.DataProvider);
        }
        
        public void Update(IDataProvider provider){
        
            
            if(this._dirtyColumns.Count>0){
                _repo.Update(this,provider);
                _dirtyColumns.Clear();    
            }
            OnSaved();
       }
 
        public void Add(){
            Add(_db.DataProvider);
        }
        
        
       
        public void Add(IDataProvider provider){

            
            var key=KeyValue();
            if(key==null){
                var newKey=_repo.Add(this,provider);
                this.SetKeyValue(newKey);
            }else{
                _repo.Add(this,provider);
            }
            SetIsNew(false);
            OnSaved();
        }
        
                
        
        public void Save() {
            Save(_db.DataProvider);
        }      
        public void Save(IDataProvider provider) {
            
           
            if (_isNew) {
                Add(provider);
                
            } else {
                Update(provider);
            }
            
        }

        

        public void Delete(IDataProvider provider) {
                   
                 
            _repo.Delete(KeyValue());
            
                    }


        public void Delete() {
            Delete(_db.DataProvider);
        }


        public static void Delete(Expression<Func<s_sprzet, bool>> expression) {
            var repo = GetRepo();
            
       
            
            repo.DeleteMany(expression);
            
        }

        

        public void Load(IDataReader rdr) {
            Load(rdr, true);
        }
        public void Load(IDataReader rdr, bool closeReader) {
            if (rdr.Read()) {

                try {
                    rdr.Load(this);
                    SetIsNew(false);
                    SetIsLoaded(true);
                } catch {
                    SetIsLoaded(false);
                    throw;
                }
            }else{
                SetIsLoaded(false);
            }

            if (closeReader)
                rdr.Dispose();
        }
        

    } 
    
    
    /// <summary>
    /// A class which represents the sale table in the evolution Database.
    /// </summary>
    public partial class sale: IActiveRecord
    {
    
        #region Built-in testing
        static TestRepository<sale> _testRepo;
        

        
        static void SetTestRepo(){
            _testRepo = _testRepo ?? new TestRepository<sale>(new Amortyzacje.Model.evolutionDB());
        }
        public static void ResetTestRepo(){
            _testRepo = null;
            SetTestRepo();
        }
        public static void Setup(List<sale> testlist){
            SetTestRepo();
            foreach (var item in testlist)
            {
                _testRepo._items.Add(item);
            }
        }
        public static void Setup(sale item) {
            SetTestRepo();
            _testRepo._items.Add(item);
        }
        public static void Setup(int testItems) {
            SetTestRepo();
            for(int i=0;i<testItems;i++){
                sale item=new sale();
                _testRepo._items.Add(item);
            }
        }
        
        public bool TestMode = false;


        #endregion

        IRepository<sale> _repo;
        ITable tbl;
        bool _isNew;
        public bool IsNew(){
            return _isNew;
        }
        
        public void SetIsLoaded(bool isLoaded){
            _isLoaded=isLoaded;
            if(isLoaded)
                OnLoaded();
        }
        
        public void SetIsNew(bool isNew){
            _isNew=isNew;
        }
        bool _isLoaded;
        public bool IsLoaded(){
            return _isLoaded;
        }
                
        List<IColumn> _dirtyColumns;
        public bool IsDirty(){
            return _dirtyColumns.Count>0;
        }
        
        public List<IColumn> GetDirtyColumns (){
            return _dirtyColumns;
        }

        Amortyzacje.Model.evolutionDB _db;
        public sale(string connectionString, string providerName) {

            _db=new Amortyzacje.Model.evolutionDB(connectionString, providerName);
            Init();            
         }
        void Init(){
            TestMode=this._db.DataProvider.ConnectionString.Equals("test", StringComparison.InvariantCultureIgnoreCase);
            _dirtyColumns=new List<IColumn>();
            if(TestMode){
                sale.SetTestRepo();
                _repo=_testRepo;
            }else{
                _repo = new SubSonicRepository<sale>(_db);
            }
            tbl=_repo.GetTable();
            SetIsNew(true);
            OnCreated();       

        }
        
        public sale(){
             _db=new Amortyzacje.Model.evolutionDB();
            Init();            
        }
        
       
        partial void OnCreated();
            
        partial void OnLoaded();
        
        partial void OnSaved();
        
        partial void OnChanged();
        
        public IList<IColumn> Columns{
            get{
                return tbl.Columns;
            }
        }

        public sale(Expression<Func<sale, bool>> expression):this() {

            SetIsLoaded(_repo.Load(this,expression));
        }
        
       
        
        internal static IRepository<sale> GetRepo(string connectionString, string providerName){
            Amortyzacje.Model.evolutionDB db;
            if(String.IsNullOrEmpty(connectionString)){
                db=new Amortyzacje.Model.evolutionDB();
            }else{
                db=new Amortyzacje.Model.evolutionDB(connectionString, providerName);
            }
            IRepository<sale> _repo;
            
            if(db.TestMode){
                sale.SetTestRepo();
                _repo=_testRepo;
            }else{
                _repo = new SubSonicRepository<sale>(db);
            }
            return _repo;        
        }       
        
        internal static IRepository<sale> GetRepo(){
            return GetRepo("","");
        }
        
        public static sale SingleOrDefault(Expression<Func<sale, bool>> expression) {

            var repo = GetRepo();
            var results=repo.Find(expression);
            sale single=null;
            if(results.Count() > 0){
                single=results.ToList()[0];
                single.OnLoaded();
                single.SetIsLoaded(true);
                single.SetIsNew(false);
            }

            return single;
        }      
        
        public static sale SingleOrDefault(Expression<Func<sale, bool>> expression,string connectionString, string providerName) {
            var repo = GetRepo(connectionString,providerName);
            var results=repo.Find(expression);
            sale single=null;
            if(results.Count() > 0){
                single=results.ToList()[0];
            }

            return single;


        }
        
        
        public static bool Exists(Expression<Func<sale, bool>> expression,string connectionString, string providerName) {
           
            return All(connectionString,providerName).Any(expression);
        }        
        public static bool Exists(Expression<Func<sale, bool>> expression) {
           
            return All().Any(expression);
        }        

        public static IList<sale> Find(Expression<Func<sale, bool>> expression) {
            
            var repo = GetRepo();
            return repo.Find(expression).ToList();
        }
        
        public static IList<sale> Find(Expression<Func<sale, bool>> expression,string connectionString, string providerName) {

            var repo = GetRepo(connectionString,providerName);
            return repo.Find(expression).ToList();

        }
        public static IQueryable<sale> All(string connectionString, string providerName) {
            return GetRepo(connectionString,providerName).GetAll();
        }
        public static IQueryable<sale> All() {
            return GetRepo().GetAll();
        }
        
        public static PagedList<sale> GetPaged(string sortBy, int pageIndex, int pageSize,string connectionString, string providerName) {
            return GetRepo(connectionString,providerName).GetPaged(sortBy, pageIndex, pageSize);
        }
      
        public static PagedList<sale> GetPaged(string sortBy, int pageIndex, int pageSize) {
            return GetRepo().GetPaged(sortBy, pageIndex, pageSize);
        }

        public static PagedList<sale> GetPaged(int pageIndex, int pageSize,string connectionString, string providerName) {
            return GetRepo(connectionString,providerName).GetPaged(pageIndex, pageSize);
            
        }


        public static PagedList<sale> GetPaged(int pageIndex, int pageSize) {
            return GetRepo().GetPaged(pageIndex, pageSize);
            
        }

        public string KeyName()
        {
            return "numer";
        }

        public object KeyValue()
        {
            return this.numer;
        }
        
        public void SetKeyValue(object value) {
            if (value != null && value!=DBNull.Value) {
                var settable = value.ChangeTypeTo<int>();
                this.GetType().GetProperty(this.KeyName()).SetValue(this, settable, null);
            }
        }
        
        public override string ToString(){
                            return this.rodzaj.ToString();
                    }

        public override bool Equals(object obj){
            if(obj.GetType()==typeof(sale)){
                sale compare=(sale)obj;
                return compare.KeyValue()==this.KeyValue();
            }else{
                return base.Equals(obj);
            }
        }

        
        public override int GetHashCode() {
            return this.numer;
        }
        
        public string DescriptorValue()
        {
                            return this.rodzaj.ToString();
                    }

        public string DescriptorColumn() {
            return "rodzaj";
        }
        public static string GetKeyColumn()
        {
            return "numer";
        }        
        public static string GetDescriptorColumn()
        {
            return "rodzaj";
        }
        
        #region ' Foreign Keys '
        #endregion
        

        int _numer;
        public int numer
        {
            get { return _numer; }
            set
            {
                if(_numer!=value){
                    _numer=value;
                    var col=tbl.Columns.SingleOrDefault(x=>x.Name=="numer");
                    if(col!=null){
                        if(!_dirtyColumns.Any(x=>x.Name==col.Name) && _isLoaded){
                            _dirtyColumns.Add(col);
                        }
                    }
                    OnChanged();
                }
            }
        }

        string _rodzaj;
        public string rodzaj
        {
            get { return _rodzaj; }
            set
            {
                if(_rodzaj!=value){
                    _rodzaj=value;
                    var col=tbl.Columns.SingleOrDefault(x=>x.Name=="rodzaj");
                    if(col!=null){
                        if(!_dirtyColumns.Any(x=>x.Name==col.Name) && _isLoaded){
                            _dirtyColumns.Add(col);
                        }
                    }
                    OnChanged();
                }
            }
        }

        int _miejsc;
        public int miejsc
        {
            get { return _miejsc; }
            set
            {
                if(_miejsc!=value){
                    _miejsc=value;
                    var col=tbl.Columns.SingleOrDefault(x=>x.Name=="miejsc");
                    if(col!=null){
                        if(!_dirtyColumns.Any(x=>x.Name==col.Name) && _isLoaded){
                            _dirtyColumns.Add(col);
                        }
                    }
                    OnChanged();
                }
            }
        }

        string _uwagi;
        public string uwagi
        {
            get { return _uwagi; }
            set
            {
                if(_uwagi!=value){
                    _uwagi=value;
                    var col=tbl.Columns.SingleOrDefault(x=>x.Name=="uwagi");
                    if(col!=null){
                        if(!_dirtyColumns.Any(x=>x.Name==col.Name) && _isLoaded){
                            _dirtyColumns.Add(col);
                        }
                    }
                    OnChanged();
                }
            }
        }



        public DbCommand GetUpdateCommand() {
            if(TestMode)
                return _db.DataProvider.CreateCommand();
            else
                return this.ToUpdateQuery(_db.Provider).GetCommand().ToDbCommand();
            
        }
        public DbCommand GetInsertCommand() {
 
            if(TestMode)
                return _db.DataProvider.CreateCommand();
            else
                return this.ToInsertQuery(_db.Provider).GetCommand().ToDbCommand();
        }
        
        public DbCommand GetDeleteCommand() {
            if(TestMode)
                return _db.DataProvider.CreateCommand();
            else
                return this.ToDeleteQuery(_db.Provider).GetCommand().ToDbCommand();
        }
       
        
        public void Update(){
            Update(_db.DataProvider);
        }
        
        public void Update(IDataProvider provider){
        
            
            if(this._dirtyColumns.Count>0){
                _repo.Update(this,provider);
                _dirtyColumns.Clear();    
            }
            OnSaved();
       }
 
        public void Add(){
            Add(_db.DataProvider);
        }
        
        
       
        public void Add(IDataProvider provider){

            
            var key=KeyValue();
            if(key==null){
                var newKey=_repo.Add(this,provider);
                this.SetKeyValue(newKey);
            }else{
                _repo.Add(this,provider);
            }
            SetIsNew(false);
            OnSaved();
        }
        
                
        
        public void Save() {
            Save(_db.DataProvider);
        }      
        public void Save(IDataProvider provider) {
            
           
            if (_isNew) {
                Add(provider);
                
            } else {
                Update(provider);
            }
            
        }

        

        public void Delete(IDataProvider provider) {
                   
                 
            _repo.Delete(KeyValue());
            
                    }


        public void Delete() {
            Delete(_db.DataProvider);
        }


        public static void Delete(Expression<Func<sale, bool>> expression) {
            var repo = GetRepo();
            
       
            
            repo.DeleteMany(expression);
            
        }

        

        public void Load(IDataReader rdr) {
            Load(rdr, true);
        }
        public void Load(IDataReader rdr, bool closeReader) {
            if (rdr.Read()) {

                try {
                    rdr.Load(this);
                    SetIsNew(false);
                    SetIsLoaded(true);
                } catch {
                    SetIsLoaded(false);
                    throw;
                }
            }else{
                SetIsLoaded(false);
            }

            if (closeReader)
                rdr.Dispose();
        }
        

    } 
    
    
    /// <summary>
    /// A class which represents the szkolenia table in the evolution Database.
    /// </summary>
    public partial class szkolenium: IActiveRecord
    {
    
        #region Built-in testing
        static TestRepository<szkolenium> _testRepo;
        

        
        static void SetTestRepo(){
            _testRepo = _testRepo ?? new TestRepository<szkolenium>(new Amortyzacje.Model.evolutionDB());
        }
        public static void ResetTestRepo(){
            _testRepo = null;
            SetTestRepo();
        }
        public static void Setup(List<szkolenium> testlist){
            SetTestRepo();
            foreach (var item in testlist)
            {
                _testRepo._items.Add(item);
            }
        }
        public static void Setup(szkolenium item) {
            SetTestRepo();
            _testRepo._items.Add(item);
        }
        public static void Setup(int testItems) {
            SetTestRepo();
            for(int i=0;i<testItems;i++){
                szkolenium item=new szkolenium();
                _testRepo._items.Add(item);
            }
        }
        
        public bool TestMode = false;


        #endregion

        IRepository<szkolenium> _repo;
        ITable tbl;
        bool _isNew;
        public bool IsNew(){
            return _isNew;
        }
        
        public void SetIsLoaded(bool isLoaded){
            _isLoaded=isLoaded;
            if(isLoaded)
                OnLoaded();
        }
        
        public void SetIsNew(bool isNew){
            _isNew=isNew;
        }
        bool _isLoaded;
        public bool IsLoaded(){
            return _isLoaded;
        }
                
        List<IColumn> _dirtyColumns;
        public bool IsDirty(){
            return _dirtyColumns.Count>0;
        }
        
        public List<IColumn> GetDirtyColumns (){
            return _dirtyColumns;
        }

        Amortyzacje.Model.evolutionDB _db;
        public szkolenium(string connectionString, string providerName) {

            _db=new Amortyzacje.Model.evolutionDB(connectionString, providerName);
            Init();            
         }
        void Init(){
            TestMode=this._db.DataProvider.ConnectionString.Equals("test", StringComparison.InvariantCultureIgnoreCase);
            _dirtyColumns=new List<IColumn>();
            if(TestMode){
                szkolenium.SetTestRepo();
                _repo=_testRepo;
            }else{
                _repo = new SubSonicRepository<szkolenium>(_db);
            }
            tbl=_repo.GetTable();
            SetIsNew(true);
            OnCreated();       

        }
        
        public szkolenium(){
             _db=new Amortyzacje.Model.evolutionDB();
            Init();            
        }
        
       
        partial void OnCreated();
            
        partial void OnLoaded();
        
        partial void OnSaved();
        
        partial void OnChanged();
        
        public IList<IColumn> Columns{
            get{
                return tbl.Columns;
            }
        }

        public szkolenium(Expression<Func<szkolenium, bool>> expression):this() {

            SetIsLoaded(_repo.Load(this,expression));
        }
        
       
        
        internal static IRepository<szkolenium> GetRepo(string connectionString, string providerName){
            Amortyzacje.Model.evolutionDB db;
            if(String.IsNullOrEmpty(connectionString)){
                db=new Amortyzacje.Model.evolutionDB();
            }else{
                db=new Amortyzacje.Model.evolutionDB(connectionString, providerName);
            }
            IRepository<szkolenium> _repo;
            
            if(db.TestMode){
                szkolenium.SetTestRepo();
                _repo=_testRepo;
            }else{
                _repo = new SubSonicRepository<szkolenium>(db);
            }
            return _repo;        
        }       
        
        internal static IRepository<szkolenium> GetRepo(){
            return GetRepo("","");
        }
        
        public static szkolenium SingleOrDefault(Expression<Func<szkolenium, bool>> expression) {

            var repo = GetRepo();
            var results=repo.Find(expression);
            szkolenium single=null;
            if(results.Count() > 0){
                single=results.ToList()[0];
                single.OnLoaded();
                single.SetIsLoaded(true);
                single.SetIsNew(false);
            }

            return single;
        }      
        
        public static szkolenium SingleOrDefault(Expression<Func<szkolenium, bool>> expression,string connectionString, string providerName) {
            var repo = GetRepo(connectionString,providerName);
            var results=repo.Find(expression);
            szkolenium single=null;
            if(results.Count() > 0){
                single=results.ToList()[0];
            }

            return single;


        }
        
        
        public static bool Exists(Expression<Func<szkolenium, bool>> expression,string connectionString, string providerName) {
           
            return All(connectionString,providerName).Any(expression);
        }        
        public static bool Exists(Expression<Func<szkolenium, bool>> expression) {
           
            return All().Any(expression);
        }        

        public static IList<szkolenium> Find(Expression<Func<szkolenium, bool>> expression) {
            
            var repo = GetRepo();
            return repo.Find(expression).ToList();
        }
        
        public static IList<szkolenium> Find(Expression<Func<szkolenium, bool>> expression,string connectionString, string providerName) {

            var repo = GetRepo(connectionString,providerName);
            return repo.Find(expression).ToList();

        }
        public static IQueryable<szkolenium> All(string connectionString, string providerName) {
            return GetRepo(connectionString,providerName).GetAll();
        }
        public static IQueryable<szkolenium> All() {
            return GetRepo().GetAll();
        }
        
        public static PagedList<szkolenium> GetPaged(string sortBy, int pageIndex, int pageSize,string connectionString, string providerName) {
            return GetRepo(connectionString,providerName).GetPaged(sortBy, pageIndex, pageSize);
        }
      
        public static PagedList<szkolenium> GetPaged(string sortBy, int pageIndex, int pageSize) {
            return GetRepo().GetPaged(sortBy, pageIndex, pageSize);
        }

        public static PagedList<szkolenium> GetPaged(int pageIndex, int pageSize,string connectionString, string providerName) {
            return GetRepo(connectionString,providerName).GetPaged(pageIndex, pageSize);
            
        }


        public static PagedList<szkolenium> GetPaged(int pageIndex, int pageSize) {
            return GetRepo().GetPaged(pageIndex, pageSize);
            
        }

        public string KeyName()
        {
            return "id";
        }

        public object KeyValue()
        {
            return this.id;
        }
        
        public void SetKeyValue(object value) {
            if (value != null && value!=DBNull.Value) {
                var settable = value.ChangeTypeTo<int>();
                this.GetType().GetProperty(this.KeyName()).SetValue(this, settable, null);
            }
        }
        
        public override string ToString(){
                            return this.rodzaj.ToString();
                    }

        public override bool Equals(object obj){
            if(obj.GetType()==typeof(szkolenium)){
                szkolenium compare=(szkolenium)obj;
                return compare.KeyValue()==this.KeyValue();
            }else{
                return base.Equals(obj);
            }
        }

        
        public override int GetHashCode() {
            return this.id;
        }
        
        public string DescriptorValue()
        {
                            return this.rodzaj.ToString();
                    }

        public string DescriptorColumn() {
            return "rodzaj";
        }
        public static string GetKeyColumn()
        {
            return "id";
        }        
        public static string GetDescriptorColumn()
        {
            return "rodzaj";
        }
        
        #region ' Foreign Keys '
        #endregion
        

        int _id;
        public int id
        {
            get { return _id; }
            set
            {
                if(_id!=value){
                    _id=value;
                    var col=tbl.Columns.SingleOrDefault(x=>x.Name=="id");
                    if(col!=null){
                        if(!_dirtyColumns.Any(x=>x.Name==col.Name) && _isLoaded){
                            _dirtyColumns.Add(col);
                        }
                    }
                    OnChanged();
                }
            }
        }

        int _nr_sali;
        public int nr_sali
        {
            get { return _nr_sali; }
            set
            {
                if(_nr_sali!=value){
                    _nr_sali=value;
                    var col=tbl.Columns.SingleOrDefault(x=>x.Name=="nr_sali");
                    if(col!=null){
                        if(!_dirtyColumns.Any(x=>x.Name==col.Name) && _isLoaded){
                            _dirtyColumns.Add(col);
                        }
                    }
                    OnChanged();
                }
            }
        }

        int _id_prelegent;
        public int id_prelegent
        {
            get { return _id_prelegent; }
            set
            {
                if(_id_prelegent!=value){
                    _id_prelegent=value;
                    var col=tbl.Columns.SingleOrDefault(x=>x.Name=="id_prelegent");
                    if(col!=null){
                        if(!_dirtyColumns.Any(x=>x.Name==col.Name) && _isLoaded){
                            _dirtyColumns.Add(col);
                        }
                    }
                    OnChanged();
                }
            }
        }

        string _rodzaj;
        public string rodzaj
        {
            get { return _rodzaj; }
            set
            {
                if(_rodzaj!=value){
                    _rodzaj=value;
                    var col=tbl.Columns.SingleOrDefault(x=>x.Name=="rodzaj");
                    if(col!=null){
                        if(!_dirtyColumns.Any(x=>x.Name==col.Name) && _isLoaded){
                            _dirtyColumns.Add(col);
                        }
                    }
                    OnChanged();
                }
            }
        }

        string _nazwa;
        public string nazwa
        {
            get { return _nazwa; }
            set
            {
                if(_nazwa!=value){
                    _nazwa=value;
                    var col=tbl.Columns.SingleOrDefault(x=>x.Name=="nazwa");
                    if(col!=null){
                        if(!_dirtyColumns.Any(x=>x.Name==col.Name) && _isLoaded){
                            _dirtyColumns.Add(col);
                        }
                    }
                    OnChanged();
                }
            }
        }

        string _opis;
        public string opis
        {
            get { return _opis; }
            set
            {
                if(_opis!=value){
                    _opis=value;
                    var col=tbl.Columns.SingleOrDefault(x=>x.Name=="opis");
                    if(col!=null){
                        if(!_dirtyColumns.Any(x=>x.Name==col.Name) && _isLoaded){
                            _dirtyColumns.Add(col);
                        }
                    }
                    OnChanged();
                }
            }
        }

        string _poziom;
        public string poziom
        {
            get { return _poziom; }
            set
            {
                if(_poziom!=value){
                    _poziom=value;
                    var col=tbl.Columns.SingleOrDefault(x=>x.Name=="poziom");
                    if(col!=null){
                        if(!_dirtyColumns.Any(x=>x.Name==col.Name) && _isLoaded){
                            _dirtyColumns.Add(col);
                        }
                    }
                    OnChanged();
                }
            }
        }

        long? _od;
        public long? od
        {
            get { return _od; }
            set
            {
                if(_od!=value){
                    _od=value;
                    var col=tbl.Columns.SingleOrDefault(x=>x.Name=="od");
                    if(col!=null){
                        if(!_dirtyColumns.Any(x=>x.Name==col.Name) && _isLoaded){
                            _dirtyColumns.Add(col);
                        }
                    }
                    OnChanged();
                }
            }
        }

        long? _do;
        public long? @do
        {
            get { return _do; }
            set
            {
                if(_do!=value){
                    _do=value;
                    var col=tbl.Columns.SingleOrDefault(x=>x.Name=="do");
                    if(col!=null){
                        if(!_dirtyColumns.Any(x=>x.Name==col.Name) && _isLoaded){
                            _dirtyColumns.Add(col);
                        }
                    }
                    OnChanged();
                }
            }
        }

        double? _cena;
        public double? cena
        {
            get { return _cena; }
            set
            {
                if(_cena!=value){
                    _cena=value;
                    var col=tbl.Columns.SingleOrDefault(x=>x.Name=="cena");
                    if(col!=null){
                        if(!_dirtyColumns.Any(x=>x.Name==col.Name) && _isLoaded){
                            _dirtyColumns.Add(col);
                        }
                    }
                    OnChanged();
                }
            }
        }

        long? _pesel_prelegenta;
        public long? pesel_prelegenta
        {
            get { return _pesel_prelegenta; }
            set
            {
                if(_pesel_prelegenta!=value){
                    _pesel_prelegenta=value;
                    var col=tbl.Columns.SingleOrDefault(x=>x.Name=="pesel_prelegenta");
                    if(col!=null){
                        if(!_dirtyColumns.Any(x=>x.Name==col.Name) && _isLoaded){
                            _dirtyColumns.Add(col);
                        }
                    }
                    OnChanged();
                }
            }
        }



        public DbCommand GetUpdateCommand() {
            if(TestMode)
                return _db.DataProvider.CreateCommand();
            else
                return this.ToUpdateQuery(_db.Provider).GetCommand().ToDbCommand();
            
        }
        public DbCommand GetInsertCommand() {
 
            if(TestMode)
                return _db.DataProvider.CreateCommand();
            else
                return this.ToInsertQuery(_db.Provider).GetCommand().ToDbCommand();
        }
        
        public DbCommand GetDeleteCommand() {
            if(TestMode)
                return _db.DataProvider.CreateCommand();
            else
                return this.ToDeleteQuery(_db.Provider).GetCommand().ToDbCommand();
        }
       
        
        public void Update(){
            Update(_db.DataProvider);
        }
        
        public void Update(IDataProvider provider){
        
            
            if(this._dirtyColumns.Count>0){
                _repo.Update(this,provider);
                _dirtyColumns.Clear();    
            }
            OnSaved();
       }
 
        public void Add(){
            Add(_db.DataProvider);
        }
        
        
       
        public void Add(IDataProvider provider){

            
            var key=KeyValue();
            if(key==null){
                var newKey=_repo.Add(this,provider);
                this.SetKeyValue(newKey);
            }else{
                _repo.Add(this,provider);
            }
            SetIsNew(false);
            OnSaved();
        }
        
                
        
        public void Save() {
            Save(_db.DataProvider);
        }      
        public void Save(IDataProvider provider) {
            
           
            if (_isNew) {
                Add(provider);
                
            } else {
                Update(provider);
            }
            
        }

        

        public void Delete(IDataProvider provider) {
                   
                 
            _repo.Delete(KeyValue());
            
                    }


        public void Delete() {
            Delete(_db.DataProvider);
        }


        public static void Delete(Expression<Func<szkolenium, bool>> expression) {
            var repo = GetRepo();
            
       
            
            repo.DeleteMany(expression);
            
        }

        

        public void Load(IDataReader rdr) {
            Load(rdr, true);
        }
        public void Load(IDataReader rdr, bool closeReader) {
            if (rdr.Read()) {

                try {
                    rdr.Load(this);
                    SetIsNew(false);
                    SetIsLoaded(true);
                } catch {
                    SetIsLoaded(false);
                    throw;
                }
            }else{
                SetIsLoaded(false);
            }

            if (closeReader)
                rdr.Dispose();
        }
        

    } 
    
    
    /// <summary>
    /// A class which represents the szkolenie_uczestnicy table in the evolution Database.
    /// </summary>
    public partial class szkolenie_uczestnicy: IActiveRecord
    {
    
        #region Built-in testing
        static TestRepository<szkolenie_uczestnicy> _testRepo;
        

        
        static void SetTestRepo(){
            _testRepo = _testRepo ?? new TestRepository<szkolenie_uczestnicy>(new Amortyzacje.Model.evolutionDB());
        }
        public static void ResetTestRepo(){
            _testRepo = null;
            SetTestRepo();
        }
        public static void Setup(List<szkolenie_uczestnicy> testlist){
            SetTestRepo();
            foreach (var item in testlist)
            {
                _testRepo._items.Add(item);
            }
        }
        public static void Setup(szkolenie_uczestnicy item) {
            SetTestRepo();
            _testRepo._items.Add(item);
        }
        public static void Setup(int testItems) {
            SetTestRepo();
            for(int i=0;i<testItems;i++){
                szkolenie_uczestnicy item=new szkolenie_uczestnicy();
                _testRepo._items.Add(item);
            }
        }
        
        public bool TestMode = false;


        #endregion

        IRepository<szkolenie_uczestnicy> _repo;
        ITable tbl;
        bool _isNew;
        public bool IsNew(){
            return _isNew;
        }
        
        public void SetIsLoaded(bool isLoaded){
            _isLoaded=isLoaded;
            if(isLoaded)
                OnLoaded();
        }
        
        public void SetIsNew(bool isNew){
            _isNew=isNew;
        }
        bool _isLoaded;
        public bool IsLoaded(){
            return _isLoaded;
        }
                
        List<IColumn> _dirtyColumns;
        public bool IsDirty(){
            return _dirtyColumns.Count>0;
        }
        
        public List<IColumn> GetDirtyColumns (){
            return _dirtyColumns;
        }

        Amortyzacje.Model.evolutionDB _db;
        public szkolenie_uczestnicy(string connectionString, string providerName) {

            _db=new Amortyzacje.Model.evolutionDB(connectionString, providerName);
            Init();            
         }
        void Init(){
            TestMode=this._db.DataProvider.ConnectionString.Equals("test", StringComparison.InvariantCultureIgnoreCase);
            _dirtyColumns=new List<IColumn>();
            if(TestMode){
                szkolenie_uczestnicy.SetTestRepo();
                _repo=_testRepo;
            }else{
                _repo = new SubSonicRepository<szkolenie_uczestnicy>(_db);
            }
            tbl=_repo.GetTable();
            SetIsNew(true);
            OnCreated();       

        }
        
        public szkolenie_uczestnicy(){
             _db=new Amortyzacje.Model.evolutionDB();
            Init();            
        }
        
       
        partial void OnCreated();
            
        partial void OnLoaded();
        
        partial void OnSaved();
        
        partial void OnChanged();
        
        public IList<IColumn> Columns{
            get{
                return tbl.Columns;
            }
        }

        public szkolenie_uczestnicy(Expression<Func<szkolenie_uczestnicy, bool>> expression):this() {

            SetIsLoaded(_repo.Load(this,expression));
        }
        
       
        
        internal static IRepository<szkolenie_uczestnicy> GetRepo(string connectionString, string providerName){
            Amortyzacje.Model.evolutionDB db;
            if(String.IsNullOrEmpty(connectionString)){
                db=new Amortyzacje.Model.evolutionDB();
            }else{
                db=new Amortyzacje.Model.evolutionDB(connectionString, providerName);
            }
            IRepository<szkolenie_uczestnicy> _repo;
            
            if(db.TestMode){
                szkolenie_uczestnicy.SetTestRepo();
                _repo=_testRepo;
            }else{
                _repo = new SubSonicRepository<szkolenie_uczestnicy>(db);
            }
            return _repo;        
        }       
        
        internal static IRepository<szkolenie_uczestnicy> GetRepo(){
            return GetRepo("","");
        }
        
        public static szkolenie_uczestnicy SingleOrDefault(Expression<Func<szkolenie_uczestnicy, bool>> expression) {

            var repo = GetRepo();
            var results=repo.Find(expression);
            szkolenie_uczestnicy single=null;
            if(results.Count() > 0){
                single=results.ToList()[0];
                single.OnLoaded();
                single.SetIsLoaded(true);
                single.SetIsNew(false);
            }

            return single;
        }      
        
        public static szkolenie_uczestnicy SingleOrDefault(Expression<Func<szkolenie_uczestnicy, bool>> expression,string connectionString, string providerName) {
            var repo = GetRepo(connectionString,providerName);
            var results=repo.Find(expression);
            szkolenie_uczestnicy single=null;
            if(results.Count() > 0){
                single=results.ToList()[0];
            }

            return single;


        }
        
        
        public static bool Exists(Expression<Func<szkolenie_uczestnicy, bool>> expression,string connectionString, string providerName) {
           
            return All(connectionString,providerName).Any(expression);
        }        
        public static bool Exists(Expression<Func<szkolenie_uczestnicy, bool>> expression) {
           
            return All().Any(expression);
        }        

        public static IList<szkolenie_uczestnicy> Find(Expression<Func<szkolenie_uczestnicy, bool>> expression) {
            
            var repo = GetRepo();
            return repo.Find(expression).ToList();
        }
        
        public static IList<szkolenie_uczestnicy> Find(Expression<Func<szkolenie_uczestnicy, bool>> expression,string connectionString, string providerName) {

            var repo = GetRepo(connectionString,providerName);
            return repo.Find(expression).ToList();

        }
        public static IQueryable<szkolenie_uczestnicy> All(string connectionString, string providerName) {
            return GetRepo(connectionString,providerName).GetAll();
        }
        public static IQueryable<szkolenie_uczestnicy> All() {
            return GetRepo().GetAll();
        }
        
        public static PagedList<szkolenie_uczestnicy> GetPaged(string sortBy, int pageIndex, int pageSize,string connectionString, string providerName) {
            return GetRepo(connectionString,providerName).GetPaged(sortBy, pageIndex, pageSize);
        }
      
        public static PagedList<szkolenie_uczestnicy> GetPaged(string sortBy, int pageIndex, int pageSize) {
            return GetRepo().GetPaged(sortBy, pageIndex, pageSize);
        }

        public static PagedList<szkolenie_uczestnicy> GetPaged(int pageIndex, int pageSize,string connectionString, string providerName) {
            return GetRepo(connectionString,providerName).GetPaged(pageIndex, pageSize);
            
        }


        public static PagedList<szkolenie_uczestnicy> GetPaged(int pageIndex, int pageSize) {
            return GetRepo().GetPaged(pageIndex, pageSize);
            
        }

        public string KeyName()
        {
            return "id";
        }

        public object KeyValue()
        {
            return this.id;
        }
        
        public void SetKeyValue(object value) {
            if (value != null && value!=DBNull.Value) {
                var settable = value.ChangeTypeTo<int>();
                this.GetType().GetProperty(this.KeyName()).SetValue(this, settable, null);
            }
        }
        
        public override string ToString(){
                            return this.id_szkolenia.ToString();
                    }

        public override bool Equals(object obj){
            if(obj.GetType()==typeof(szkolenie_uczestnicy)){
                szkolenie_uczestnicy compare=(szkolenie_uczestnicy)obj;
                return compare.KeyValue()==this.KeyValue();
            }else{
                return base.Equals(obj);
            }
        }

        
        public override int GetHashCode() {
            return this.id;
        }
        
        public string DescriptorValue()
        {
                            return this.id_szkolenia.ToString();
                    }

        public string DescriptorColumn() {
            return "id_szkolenia";
        }
        public static string GetKeyColumn()
        {
            return "id";
        }        
        public static string GetDescriptorColumn()
        {
            return "id_szkolenia";
        }
        
        #region ' Foreign Keys '
        #endregion
        

        int _id;
        public int id
        {
            get { return _id; }
            set
            {
                if(_id!=value){
                    _id=value;
                    var col=tbl.Columns.SingleOrDefault(x=>x.Name=="id");
                    if(col!=null){
                        if(!_dirtyColumns.Any(x=>x.Name==col.Name) && _isLoaded){
                            _dirtyColumns.Add(col);
                        }
                    }
                    OnChanged();
                }
            }
        }

        int _id_szkolenia;
        public int id_szkolenia
        {
            get { return _id_szkolenia; }
            set
            {
                if(_id_szkolenia!=value){
                    _id_szkolenia=value;
                    var col=tbl.Columns.SingleOrDefault(x=>x.Name=="id_szkolenia");
                    if(col!=null){
                        if(!_dirtyColumns.Any(x=>x.Name==col.Name) && _isLoaded){
                            _dirtyColumns.Add(col);
                        }
                    }
                    OnChanged();
                }
            }
        }

        long _pesel;
        public long pesel
        {
            get { return _pesel; }
            set
            {
                if(_pesel!=value){
                    _pesel=value;
                    var col=tbl.Columns.SingleOrDefault(x=>x.Name=="pesel");
                    if(col!=null){
                        if(!_dirtyColumns.Any(x=>x.Name==col.Name) && _isLoaded){
                            _dirtyColumns.Add(col);
                        }
                    }
                    OnChanged();
                }
            }
        }



        public DbCommand GetUpdateCommand() {
            if(TestMode)
                return _db.DataProvider.CreateCommand();
            else
                return this.ToUpdateQuery(_db.Provider).GetCommand().ToDbCommand();
            
        }
        public DbCommand GetInsertCommand() {
 
            if(TestMode)
                return _db.DataProvider.CreateCommand();
            else
                return this.ToInsertQuery(_db.Provider).GetCommand().ToDbCommand();
        }
        
        public DbCommand GetDeleteCommand() {
            if(TestMode)
                return _db.DataProvider.CreateCommand();
            else
                return this.ToDeleteQuery(_db.Provider).GetCommand().ToDbCommand();
        }
       
        
        public void Update(){
            Update(_db.DataProvider);
        }
        
        public void Update(IDataProvider provider){
        
            
            if(this._dirtyColumns.Count>0){
                _repo.Update(this,provider);
                _dirtyColumns.Clear();    
            }
            OnSaved();
       }
 
        public void Add(){
            Add(_db.DataProvider);
        }
        
        
       
        public void Add(IDataProvider provider){

            
            var key=KeyValue();
            if(key==null){
                var newKey=_repo.Add(this,provider);
                this.SetKeyValue(newKey);
            }else{
                _repo.Add(this,provider);
            }
            SetIsNew(false);
            OnSaved();
        }
        
                
        
        public void Save() {
            Save(_db.DataProvider);
        }      
        public void Save(IDataProvider provider) {
            
           
            if (_isNew) {
                Add(provider);
                
            } else {
                Update(provider);
            }
            
        }

        

        public void Delete(IDataProvider provider) {
                   
                 
            _repo.Delete(KeyValue());
            
                    }


        public void Delete() {
            Delete(_db.DataProvider);
        }


        public static void Delete(Expression<Func<szkolenie_uczestnicy, bool>> expression) {
            var repo = GetRepo();
            
       
            
            repo.DeleteMany(expression);
            
        }

        

        public void Load(IDataReader rdr) {
            Load(rdr, true);
        }
        public void Load(IDataReader rdr, bool closeReader) {
            if (rdr.Read()) {

                try {
                    rdr.Load(this);
                    SetIsNew(false);
                    SetIsLoaded(true);
                } catch {
                    SetIsLoaded(false);
                    throw;
                }
            }else{
                SetIsLoaded(false);
            }

            if (closeReader)
                rdr.Dispose();
        }
        

    } 
    
    
    /// <summary>
    /// A class which represents the uczestnicy table in the evolution Database.
    /// </summary>
    public partial class uczestnicy: IActiveRecord
    {
    
        #region Built-in testing
        static TestRepository<uczestnicy> _testRepo;
        

        
        static void SetTestRepo(){
            _testRepo = _testRepo ?? new TestRepository<uczestnicy>(new Amortyzacje.Model.evolutionDB());
        }
        public static void ResetTestRepo(){
            _testRepo = null;
            SetTestRepo();
        }
        public static void Setup(List<uczestnicy> testlist){
            SetTestRepo();
            foreach (var item in testlist)
            {
                _testRepo._items.Add(item);
            }
        }
        public static void Setup(uczestnicy item) {
            SetTestRepo();
            _testRepo._items.Add(item);
        }
        public static void Setup(int testItems) {
            SetTestRepo();
            for(int i=0;i<testItems;i++){
                uczestnicy item=new uczestnicy();
                _testRepo._items.Add(item);
            }
        }
        
        public bool TestMode = false;


        #endregion

        IRepository<uczestnicy> _repo;
        ITable tbl;
        bool _isNew;
        public bool IsNew(){
            return _isNew;
        }
        
        public void SetIsLoaded(bool isLoaded){
            _isLoaded=isLoaded;
            if(isLoaded)
                OnLoaded();
        }
        
        public void SetIsNew(bool isNew){
            _isNew=isNew;
        }
        bool _isLoaded;
        public bool IsLoaded(){
            return _isLoaded;
        }
                
        List<IColumn> _dirtyColumns;
        public bool IsDirty(){
            return _dirtyColumns.Count>0;
        }
        
        public List<IColumn> GetDirtyColumns (){
            return _dirtyColumns;
        }

        Amortyzacje.Model.evolutionDB _db;
        public uczestnicy(string connectionString, string providerName) {

            _db=new Amortyzacje.Model.evolutionDB(connectionString, providerName);
            Init();            
         }
        void Init(){
            TestMode=this._db.DataProvider.ConnectionString.Equals("test", StringComparison.InvariantCultureIgnoreCase);
            _dirtyColumns=new List<IColumn>();
            if(TestMode){
                uczestnicy.SetTestRepo();
                _repo=_testRepo;
            }else{
                _repo = new SubSonicRepository<uczestnicy>(_db);
            }
            tbl=_repo.GetTable();
            SetIsNew(true);
            OnCreated();       

        }
        
        public uczestnicy(){
             _db=new Amortyzacje.Model.evolutionDB();
            Init();            
        }
        
       
        partial void OnCreated();
            
        partial void OnLoaded();
        
        partial void OnSaved();
        
        partial void OnChanged();
        
        public IList<IColumn> Columns{
            get{
                return tbl.Columns;
            }
        }

        public uczestnicy(Expression<Func<uczestnicy, bool>> expression):this() {

            SetIsLoaded(_repo.Load(this,expression));
        }
        
       
        
        internal static IRepository<uczestnicy> GetRepo(string connectionString, string providerName){
            Amortyzacje.Model.evolutionDB db;
            if(String.IsNullOrEmpty(connectionString)){
                db=new Amortyzacje.Model.evolutionDB();
            }else{
                db=new Amortyzacje.Model.evolutionDB(connectionString, providerName);
            }
            IRepository<uczestnicy> _repo;
            
            if(db.TestMode){
                uczestnicy.SetTestRepo();
                _repo=_testRepo;
            }else{
                _repo = new SubSonicRepository<uczestnicy>(db);
            }
            return _repo;        
        }       
        
        internal static IRepository<uczestnicy> GetRepo(){
            return GetRepo("","");
        }
        
        public static uczestnicy SingleOrDefault(Expression<Func<uczestnicy, bool>> expression) {

            var repo = GetRepo();
            var results=repo.Find(expression);
            uczestnicy single=null;
            if(results.Count() > 0){
                single=results.ToList()[0];
                single.OnLoaded();
                single.SetIsLoaded(true);
                single.SetIsNew(false);
            }

            return single;
        }      
        
        public static uczestnicy SingleOrDefault(Expression<Func<uczestnicy, bool>> expression,string connectionString, string providerName) {
            var repo = GetRepo(connectionString,providerName);
            var results=repo.Find(expression);
            uczestnicy single=null;
            if(results.Count() > 0){
                single=results.ToList()[0];
            }

            return single;


        }
        
        
        public static bool Exists(Expression<Func<uczestnicy, bool>> expression,string connectionString, string providerName) {
           
            return All(connectionString,providerName).Any(expression);
        }        
        public static bool Exists(Expression<Func<uczestnicy, bool>> expression) {
           
            return All().Any(expression);
        }        

        public static IList<uczestnicy> Find(Expression<Func<uczestnicy, bool>> expression) {
            
            var repo = GetRepo();
            return repo.Find(expression).ToList();
        }
        
        public static IList<uczestnicy> Find(Expression<Func<uczestnicy, bool>> expression,string connectionString, string providerName) {

            var repo = GetRepo(connectionString,providerName);
            return repo.Find(expression).ToList();

        }
        public static IQueryable<uczestnicy> All(string connectionString, string providerName) {
            return GetRepo(connectionString,providerName).GetAll();
        }
        public static IQueryable<uczestnicy> All() {
            return GetRepo().GetAll();
        }
        
        public static PagedList<uczestnicy> GetPaged(string sortBy, int pageIndex, int pageSize,string connectionString, string providerName) {
            return GetRepo(connectionString,providerName).GetPaged(sortBy, pageIndex, pageSize);
        }
      
        public static PagedList<uczestnicy> GetPaged(string sortBy, int pageIndex, int pageSize) {
            return GetRepo().GetPaged(sortBy, pageIndex, pageSize);
        }

        public static PagedList<uczestnicy> GetPaged(int pageIndex, int pageSize,string connectionString, string providerName) {
            return GetRepo(connectionString,providerName).GetPaged(pageIndex, pageSize);
            
        }


        public static PagedList<uczestnicy> GetPaged(int pageIndex, int pageSize) {
            return GetRepo().GetPaged(pageIndex, pageSize);
            
        }

        public string KeyName()
        {
            return "pesel";
        }

        public object KeyValue()
        {
            return this.pesel;
        }
        
        public void SetKeyValue(object value) {
            if (value != null && value!=DBNull.Value) {
                var settable = value.ChangeTypeTo<long>();
                this.GetType().GetProperty(this.KeyName()).SetValue(this, settable, null);
            }
        }
        
        public override string ToString(){
                            return this.imie.ToString();
                    }

        public override bool Equals(object obj){
            if(obj.GetType()==typeof(uczestnicy)){
                uczestnicy compare=(uczestnicy)obj;
                return compare.KeyValue()==this.KeyValue();
            }else{
                return base.Equals(obj);
            }
        }

        public string DescriptorValue()
        {
                            return this.imie.ToString();
                    }

        public string DescriptorColumn() {
            return "imie";
        }
        public static string GetKeyColumn()
        {
            return "pesel";
        }        
        public static string GetDescriptorColumn()
        {
            return "imie";
        }
        
        #region ' Foreign Keys '
        #endregion
        

        long _pesel;
        public long pesel
        {
            get { return _pesel; }
            set
            {
                if(_pesel!=value){
                    _pesel=value;
                    var col=tbl.Columns.SingleOrDefault(x=>x.Name=="pesel");
                    if(col!=null){
                        if(!_dirtyColumns.Any(x=>x.Name==col.Name) && _isLoaded){
                            _dirtyColumns.Add(col);
                        }
                    }
                    OnChanged();
                }
            }
        }

        string _imie;
        public string imie
        {
            get { return _imie; }
            set
            {
                if(_imie!=value){
                    _imie=value;
                    var col=tbl.Columns.SingleOrDefault(x=>x.Name=="imie");
                    if(col!=null){
                        if(!_dirtyColumns.Any(x=>x.Name==col.Name) && _isLoaded){
                            _dirtyColumns.Add(col);
                        }
                    }
                    OnChanged();
                }
            }
        }

        string _nazwisko;
        public string nazwisko
        {
            get { return _nazwisko; }
            set
            {
                if(_nazwisko!=value){
                    _nazwisko=value;
                    var col=tbl.Columns.SingleOrDefault(x=>x.Name=="nazwisko");
                    if(col!=null){
                        if(!_dirtyColumns.Any(x=>x.Name==col.Name) && _isLoaded){
                            _dirtyColumns.Add(col);
                        }
                    }
                    OnChanged();
                }
            }
        }

        string _nrtel;
        public string nrtel
        {
            get { return _nrtel; }
            set
            {
                if(_nrtel!=value){
                    _nrtel=value;
                    var col=tbl.Columns.SingleOrDefault(x=>x.Name=="nr tel");
                    if(col!=null){
                        if(!_dirtyColumns.Any(x=>x.Name==col.Name) && _isLoaded){
                            _dirtyColumns.Add(col);
                        }
                    }
                    OnChanged();
                }
            }
        }

        string _email;
        public string email
        {
            get { return _email; }
            set
            {
                if(_email!=value){
                    _email=value;
                    var col=tbl.Columns.SingleOrDefault(x=>x.Name=="email");
                    if(col!=null){
                        if(!_dirtyColumns.Any(x=>x.Name==col.Name) && _isLoaded){
                            _dirtyColumns.Add(col);
                        }
                    }
                    OnChanged();
                }
            }
        }

        int? _naleznosc;
        public int? naleznosc
        {
            get { return _naleznosc; }
            set
            {
                if(_naleznosc!=value){
                    _naleznosc=value;
                    var col=tbl.Columns.SingleOrDefault(x=>x.Name=="naleznosc");
                    if(col!=null){
                        if(!_dirtyColumns.Any(x=>x.Name==col.Name) && _isLoaded){
                            _dirtyColumns.Add(col);
                        }
                    }
                    OnChanged();
                }
            }
        }

        string _adres;
        public string adres
        {
            get { return _adres; }
            set
            {
                if(_adres!=value){
                    _adres=value;
                    var col=tbl.Columns.SingleOrDefault(x=>x.Name=="adres");
                    if(col!=null){
                        if(!_dirtyColumns.Any(x=>x.Name==col.Name) && _isLoaded){
                            _dirtyColumns.Add(col);
                        }
                    }
                    OnChanged();
                }
            }
        }

        string _miejscowosc;
        public string miejscowosc
        {
            get { return _miejscowosc; }
            set
            {
                if(_miejscowosc!=value){
                    _miejscowosc=value;
                    var col=tbl.Columns.SingleOrDefault(x=>x.Name=="miejscowosc");
                    if(col!=null){
                        if(!_dirtyColumns.Any(x=>x.Name==col.Name) && _isLoaded){
                            _dirtyColumns.Add(col);
                        }
                    }
                    OnChanged();
                }
            }
        }

        string _kod;
        public string kod
        {
            get { return _kod; }
            set
            {
                if(_kod!=value){
                    _kod=value;
                    var col=tbl.Columns.SingleOrDefault(x=>x.Name=="kod");
                    if(col!=null){
                        if(!_dirtyColumns.Any(x=>x.Name==col.Name) && _isLoaded){
                            _dirtyColumns.Add(col);
                        }
                    }
                    OnChanged();
                }
            }
        }

        DateTime? _dataUr;
        public DateTime? dataUr
        {
            get { return _dataUr; }
            set
            {
                if(_dataUr!=value){
                    _dataUr=value;
                    var col=tbl.Columns.SingleOrDefault(x=>x.Name=="dataUr");
                    if(col!=null){
                        if(!_dirtyColumns.Any(x=>x.Name==col.Name) && _isLoaded){
                            _dirtyColumns.Add(col);
                        }
                    }
                    OnChanged();
                }
            }
        }



        public DbCommand GetUpdateCommand() {
            if(TestMode)
                return _db.DataProvider.CreateCommand();
            else
                return this.ToUpdateQuery(_db.Provider).GetCommand().ToDbCommand();
            
        }
        public DbCommand GetInsertCommand() {
 
            if(TestMode)
                return _db.DataProvider.CreateCommand();
            else
                return this.ToInsertQuery(_db.Provider).GetCommand().ToDbCommand();
        }
        
        public DbCommand GetDeleteCommand() {
            if(TestMode)
                return _db.DataProvider.CreateCommand();
            else
                return this.ToDeleteQuery(_db.Provider).GetCommand().ToDbCommand();
        }
       
        
        public void Update(){
            Update(_db.DataProvider);
        }
        
        public void Update(IDataProvider provider){
        
            
            if(this._dirtyColumns.Count>0){
                _repo.Update(this,provider);
                _dirtyColumns.Clear();    
            }
            OnSaved();
       }
 
        public void Add(){
            Add(_db.DataProvider);
        }
        
        
       
        public void Add(IDataProvider provider){

            
            var key=KeyValue();
            if(key==null){
                var newKey=_repo.Add(this,provider);
                this.SetKeyValue(newKey);
            }else{
                _repo.Add(this,provider);
            }
            SetIsNew(false);
            OnSaved();
        }
        
                
        
        public void Save() {
            Save(_db.DataProvider);
        }      
        public void Save(IDataProvider provider) {
            
           
            if (_isNew) {
                Add(provider);
                
            } else {
                Update(provider);
            }
            
        }

        

        public void Delete(IDataProvider provider) {
                   
                 
            _repo.Delete(KeyValue());
            
                    }


        public void Delete() {
            Delete(_db.DataProvider);
        }


        public static void Delete(Expression<Func<uczestnicy, bool>> expression) {
            var repo = GetRepo();
            
       
            
            repo.DeleteMany(expression);
            
        }

        

        public void Load(IDataReader rdr) {
            Load(rdr, true);
        }
        public void Load(IDataReader rdr, bool closeReader) {
            if (rdr.Read()) {

                try {
                    rdr.Load(this);
                    SetIsNew(false);
                    SetIsLoaded(true);
                } catch {
                    SetIsLoaded(false);
                    throw;
                }
            }else{
                SetIsLoaded(false);
            }

            if (closeReader)
                rdr.Dispose();
        }
        

    } 
    
    
    /// <summary>
    /// A class which represents the users table in the evolution Database.
    /// </summary>
    public partial class user: IActiveRecord
    {
    
        #region Built-in testing
        static TestRepository<user> _testRepo;
        

        
        static void SetTestRepo(){
            _testRepo = _testRepo ?? new TestRepository<user>(new Amortyzacje.Model.evolutionDB());
        }
        public static void ResetTestRepo(){
            _testRepo = null;
            SetTestRepo();
        }
        public static void Setup(List<user> testlist){
            SetTestRepo();
            foreach (var item in testlist)
            {
                _testRepo._items.Add(item);
            }
        }
        public static void Setup(user item) {
            SetTestRepo();
            _testRepo._items.Add(item);
        }
        public static void Setup(int testItems) {
            SetTestRepo();
            for(int i=0;i<testItems;i++){
                user item=new user();
                _testRepo._items.Add(item);
            }
        }
        
        public bool TestMode = false;


        #endregion

        IRepository<user> _repo;
        ITable tbl;
        bool _isNew;
        public bool IsNew(){
            return _isNew;
        }
        
        public void SetIsLoaded(bool isLoaded){
            _isLoaded=isLoaded;
            if(isLoaded)
                OnLoaded();
        }
        
        public void SetIsNew(bool isNew){
            _isNew=isNew;
        }
        bool _isLoaded;
        public bool IsLoaded(){
            return _isLoaded;
        }
                
        List<IColumn> _dirtyColumns;
        public bool IsDirty(){
            return _dirtyColumns.Count>0;
        }
        
        public List<IColumn> GetDirtyColumns (){
            return _dirtyColumns;
        }

        Amortyzacje.Model.evolutionDB _db;
        public user(string connectionString, string providerName) {

            _db=new Amortyzacje.Model.evolutionDB(connectionString, providerName);
            Init();            
         }
        void Init(){
            TestMode=this._db.DataProvider.ConnectionString.Equals("test", StringComparison.InvariantCultureIgnoreCase);
            _dirtyColumns=new List<IColumn>();
            if(TestMode){
                user.SetTestRepo();
                _repo=_testRepo;
            }else{
                _repo = new SubSonicRepository<user>(_db);
            }
            tbl=_repo.GetTable();
            SetIsNew(true);
            OnCreated();       

        }
        
        public user(){
             _db=new Amortyzacje.Model.evolutionDB();
            Init();            
        }
        
       
        partial void OnCreated();
            
        partial void OnLoaded();
        
        partial void OnSaved();
        
        partial void OnChanged();
        
        public IList<IColumn> Columns{
            get{
                return tbl.Columns;
            }
        }

        public user(Expression<Func<user, bool>> expression):this() {

            SetIsLoaded(_repo.Load(this,expression));
        }
        
       
        
        internal static IRepository<user> GetRepo(string connectionString, string providerName){
            Amortyzacje.Model.evolutionDB db;
            if(String.IsNullOrEmpty(connectionString)){
                db=new Amortyzacje.Model.evolutionDB();
            }else{
                db=new Amortyzacje.Model.evolutionDB(connectionString, providerName);
            }
            IRepository<user> _repo;
            
            if(db.TestMode){
                user.SetTestRepo();
                _repo=_testRepo;
            }else{
                _repo = new SubSonicRepository<user>(db);
            }
            return _repo;        
        }       
        
        internal static IRepository<user> GetRepo(){
            return GetRepo("","");
        }
        
        public static user SingleOrDefault(Expression<Func<user, bool>> expression) {

            var repo = GetRepo();
            var results=repo.Find(expression);
            user single=null;
            if(results.Count() > 0){
                single=results.ToList()[0];
                single.OnLoaded();
                single.SetIsLoaded(true);
                single.SetIsNew(false);
            }

            return single;
        }      
        
        public static user SingleOrDefault(Expression<Func<user, bool>> expression,string connectionString, string providerName) {
            var repo = GetRepo(connectionString,providerName);
            var results=repo.Find(expression);
            user single=null;
            if(results.Count() > 0){
                single=results.ToList()[0];
            }

            return single;


        }
        
        
        public static bool Exists(Expression<Func<user, bool>> expression,string connectionString, string providerName) {
           
            return All(connectionString,providerName).Any(expression);
        }        
        public static bool Exists(Expression<Func<user, bool>> expression) {
           
            return All().Any(expression);
        }        

        public static IList<user> Find(Expression<Func<user, bool>> expression) {
            
            var repo = GetRepo();
            return repo.Find(expression).ToList();
        }
        
        public static IList<user> Find(Expression<Func<user, bool>> expression,string connectionString, string providerName) {

            var repo = GetRepo(connectionString,providerName);
            return repo.Find(expression).ToList();

        }
        public static IQueryable<user> All(string connectionString, string providerName) {
            return GetRepo(connectionString,providerName).GetAll();
        }
        public static IQueryable<user> All() {
            return GetRepo().GetAll();
        }
        
        public static PagedList<user> GetPaged(string sortBy, int pageIndex, int pageSize,string connectionString, string providerName) {
            return GetRepo(connectionString,providerName).GetPaged(sortBy, pageIndex, pageSize);
        }
      
        public static PagedList<user> GetPaged(string sortBy, int pageIndex, int pageSize) {
            return GetRepo().GetPaged(sortBy, pageIndex, pageSize);
        }

        public static PagedList<user> GetPaged(int pageIndex, int pageSize,string connectionString, string providerName) {
            return GetRepo(connectionString,providerName).GetPaged(pageIndex, pageSize);
            
        }


        public static PagedList<user> GetPaged(int pageIndex, int pageSize) {
            return GetRepo().GetPaged(pageIndex, pageSize);
            
        }

        public string KeyName()
        {
            return "id";
        }

        public object KeyValue()
        {
            return this.id;
        }
        
        public void SetKeyValue(object value) {
            if (value != null && value!=DBNull.Value) {
                var settable = value.ChangeTypeTo<int>();
                this.GetType().GetProperty(this.KeyName()).SetValue(this, settable, null);
            }
        }
        
        public override string ToString(){
                            return this.login.ToString();
                    }

        public override bool Equals(object obj){
            if(obj.GetType()==typeof(user)){
                user compare=(user)obj;
                return compare.KeyValue()==this.KeyValue();
            }else{
                return base.Equals(obj);
            }
        }

        
        public override int GetHashCode() {
            return this.id;
        }
        
        public string DescriptorValue()
        {
                            return this.login.ToString();
                    }

        public string DescriptorColumn() {
            return "login";
        }
        public static string GetKeyColumn()
        {
            return "id";
        }        
        public static string GetDescriptorColumn()
        {
            return "login";
        }
        
        #region ' Foreign Keys '
        #endregion
        

        int _id;
        public int id
        {
            get { return _id; }
            set
            {
                if(_id!=value){
                    _id=value;
                    var col=tbl.Columns.SingleOrDefault(x=>x.Name=="id");
                    if(col!=null){
                        if(!_dirtyColumns.Any(x=>x.Name==col.Name) && _isLoaded){
                            _dirtyColumns.Add(col);
                        }
                    }
                    OnChanged();
                }
            }
        }

        string _login;
        public string login
        {
            get { return _login; }
            set
            {
                if(_login!=value){
                    _login=value;
                    var col=tbl.Columns.SingleOrDefault(x=>x.Name=="login");
                    if(col!=null){
                        if(!_dirtyColumns.Any(x=>x.Name==col.Name) && _isLoaded){
                            _dirtyColumns.Add(col);
                        }
                    }
                    OnChanged();
                }
            }
        }

        string _password;
        public string password
        {
            get { return _password; }
            set
            {
                if(_password!=value){
                    _password=value;
                    var col=tbl.Columns.SingleOrDefault(x=>x.Name=="password");
                    if(col!=null){
                        if(!_dirtyColumns.Any(x=>x.Name==col.Name) && _isLoaded){
                            _dirtyColumns.Add(col);
                        }
                    }
                    OnChanged();
                }
            }
        }



        public DbCommand GetUpdateCommand() {
            if(TestMode)
                return _db.DataProvider.CreateCommand();
            else
                return this.ToUpdateQuery(_db.Provider).GetCommand().ToDbCommand();
            
        }
        public DbCommand GetInsertCommand() {
 
            if(TestMode)
                return _db.DataProvider.CreateCommand();
            else
                return this.ToInsertQuery(_db.Provider).GetCommand().ToDbCommand();
        }
        
        public DbCommand GetDeleteCommand() {
            if(TestMode)
                return _db.DataProvider.CreateCommand();
            else
                return this.ToDeleteQuery(_db.Provider).GetCommand().ToDbCommand();
        }
       
        
        public void Update(){
            Update(_db.DataProvider);
        }
        
        public void Update(IDataProvider provider){
        
            
            if(this._dirtyColumns.Count>0){
                _repo.Update(this,provider);
                _dirtyColumns.Clear();    
            }
            OnSaved();
       }
 
        public void Add(){
            Add(_db.DataProvider);
        }
        
        
       
        public void Add(IDataProvider provider){

            
            var key=KeyValue();
            if(key==null){
                var newKey=_repo.Add(this,provider);
                this.SetKeyValue(newKey);
            }else{
                _repo.Add(this,provider);
            }
            SetIsNew(false);
            OnSaved();
        }
        
                
        
        public void Save() {
            Save(_db.DataProvider);
        }      
        public void Save(IDataProvider provider) {
            
           
            if (_isNew) {
                Add(provider);
                
            } else {
                Update(provider);
            }
            
        }

        

        public void Delete(IDataProvider provider) {
                   
                 
            _repo.Delete(KeyValue());
            
                    }


        public void Delete() {
            Delete(_db.DataProvider);
        }


        public static void Delete(Expression<Func<user, bool>> expression) {
            var repo = GetRepo();
            
       
            
            repo.DeleteMany(expression);
            
        }

        

        public void Load(IDataReader rdr) {
            Load(rdr, true);
        }
        public void Load(IDataReader rdr, bool closeReader) {
            if (rdr.Read()) {

                try {
                    rdr.Load(this);
                    SetIsNew(false);
                    SetIsLoaded(true);
                } catch {
                    SetIsLoaded(false);
                    throw;
                }
            }else{
                SetIsLoaded(false);
            }

            if (closeReader)
                rdr.Dispose();
        }
        

    } 
}
